ソースコード読んだり、実際に処理系を動かしてみたメモを残しておきます。内容は当然ながら無保証です。 基本的に難しいことはやっていないので、ソースを読めばだいたいわかります。
C++で書かれている。
字句解析(flex) → 構文解析(bison)→ コード生成(LLVM IRを生成)
って感じで特に変なことはしていない。LLVM IR使っているというのが今どきぽいけど。
function doPost(e) { | |
// slack appsのEvent Subscriptionsのchallenge。同期する時に利用。 | |
var params = JSON.parse(e.postData.getDataAsString()); | |
if('challenge' in params) | |
{ | |
return ContentService.createTextOutput(params.challenge); | |
} | |
// ユーザ名とtextを取得 | |
var userName = params.event.user; |
もちろんです!以下に、Chrome拡張機能を作成するためのコードの例を示します。これは、指定された仕様を満たすシンプルな拡張機能です。 | |
まず、プロジェクトディレクトリに3つのファイルを作成してください。 | |
manifest.json | |
background.js | |
content.js | |
manifest.json: |
//This implementation is a porting of naive continuation monad in Haskell in "All About Monads" pages. | |
class Cont[R, +A](val runCont: (A => R) => R) { | |
def map[B](f: A => B): Cont[R, B] = { | |
new Cont[R, B](k => runCont(a => Cont.ret[R, B](f(a)).runCont(k))) | |
} | |
def flatMap[B](f: A => Cont[R, B]) :Cont[R, B] = { | |
new Cont[R, B](k => runCont(a => f(a).runCont(k))) | |
} | |
} |
以下の日本語をプログラムとして解釈して実行してください。 | |
ほげ数を計算(N) | |
・もし、N < 2 なら1を返す | |
・そうでなければ、「N * ほげ数を計算(N - 1)」を返す | |
ほげ数を計算(10) |
import strutils | |
import lists | |
import re | |
type | |
Parser[T] = proc(input: string): Maybe[(T, string)] | |
Maybe*[T] = object | |
value: T | |
hasValue: bool |
.class public DifferentReturnTypes | |
.super java/lang/Object | |
; | |
; standard initializer | |
.method public <init>()V | |
aload_0 | |
invokenonvirtual java/lang/Object/<init>()V | |
return |
scala> def from(n: Int): LazyList[Int] = LazyList.cons(n, from(n + 1)) | |
def from(n: Int): LazyList[Int] | |
scala> from(0).take(10).toList | |
val res0: List[Int] = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) |
trait Visitors { | |
type V <: Visitor | |
type E <: Expression | |
trait Visitor { | |
def visit(e: Addition): Int | |
def visit(e: Subtraction): Int | |
def visit(e: Multiplication): Int | |
def visit(e: Num): Int | |
} |
import com.github.kmizu.scomb._ | |
object Calculator1 extends SCombinator[Int] { | |
def root: Parser[Int] = expression | |
def expression: Parser[Int] = rule(A) | |
def A: Parser[Int] = rule(chainl(M) { | |
$("+").map { op => (lhs: Int, rhs: Int) => lhs + rhs } | | |
$("-").map { op => (lhs: Int, rhs: Int) => lhs - rhs } |