More Related Content
BoostAsioで可読性を求めるのは間違っているだろうか Python で munin plugin を書いてみる Fork/Join Framework。そしてLambdaへ。 What's hot (20)
C++コンパイラ GCCとClangからのメッセージをお読みください Real World OCamlを読んでLispと協調してみた Effective Modern C++ 読書会 Item 35 Viewers also liked (7)
Programming Haskell Chapter 11 切符番号選び Similar to Scalamacrosについて (20)
Everyday Life with clojure.spec 並列対決 Elixir × Go × C# x Scala , Node.js 思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8 From Scala/Clojure to Kotlin Kobe.R #15 - Incanter チョットシッテル More from dekosuke (6)
Machine learning @ PyFes 2011.10 Scalamacrosについて
- 8. マクロの悪名
C言語のマクロは悪名高い
そもそもC++のテンプレートが提案された理由
はC言語マクロほど凶悪でないプリプロセッサ
がほしからでした
8
- 11. 例: 型安全なprintf (関数マクロ)
//こんなマクロを書くと
macro def printf(format: String, params: Any*) {
val (evals, refs) = parse(format, params)
val seq = evals + refs.map(x => c"print($x)")
c"$seq"
}
//型安全なprintfが
printf("Value = %d", 123 + 877)
//こう展開されるよ
val p1 = (123 + 877): Int
print("Value = "); print(p1)
11
- 12. 例:DB (型マクロ)
macro trait MySqlDb(connString: String) = …
type MyDb = Base with
MySqlDb("Server=127.0.0.1;Database=Foo;")
Scalaの文法の自然な拡張(意味のないおまじな
いを増やさない)
12
- 13. Boilerplate
言語のおまじない
「すべてのBoilerplateを消し去りたい!」
trait TupledFunctions extends Functions with TupleOps { implicit def
fun[A1:Manifest,A2:Manifest,B:Manifest](f: (Rep[A1], Rep[A2]) =>
Rep[B]) : Rep[((A1,A2))=>B] = fun((t: Rep[(A1,A2)]) => f(tuple2_get1(t),
tuple2_get2(t))) implicit def
fun[A1:Manifest,A2:Manifest,A3:Manifest,B:Manifest](f: (Rep[A1],
Rep[A2], Rep[A3]) => Rep[B]) : Rep[((A1,A2,A3))=>B] = fun((t:
Rep[(A1,A2,A3)]) => f(tuple3_get1(t), tuple3_get2(t),
tuple3_get3(t))) ... } 13
- 16. 作者HP
作者HP見ると時系列的な進行が分かるよ!
http://xeno-by.blogspot.com/
16