やっぱりメソッド呼び出しを . で始めるようにした
関数位置に置けるのは、関数を表すシンボルと lambda フォーム、proc フォーム、そして meth フォーム。. は meth フォームを生成するリードマクロだ。
ラムダ
> ((lambda (x) (.* x 2)) 3) read: [[:lambda, [:x], [[:meth, :*], :x, 2]], 3] ruby: lambda { |x| x.*(2) }.call(3) 6
シンボル
> (puts "hello") read: [:puts, "hello"] ruby: puts("hello") hello nil
メソッド名
> (.odd? 1) read: [[:meth, :odd?], 1] ruby: 1.odd?() true
function フォームとの相互作用
meth フォームは function フォーム(#')の補語になると Proc オブジェクトに評価される。
> (.call #'.odd? 1) read: [[:meth, :call], [:function, [:meth, :odd?]], 1] ruby: :odd?.to_proc.call(1) true
シンボルは Method オブジェクト。
> (.call #'puts "hello") read: [[:meth, :call], [:function, :puts], "hello"] ruby: method(:puts).call("hello") hello nil
ブロック引数
& シンボルの前置でブロック引数を表すのをやめた。barg フォーム(#&) でブロック引数渡しができる。関数適用の引数の位置でないと合法的に評価できないのが悩ましい。
> (.map '(1 2 3) #&.odd?) read: [[:meth, :map], [:quote, [1, 2, 3]], [:barg, [:function, [:meth, :odd?]]]] ruby: [1, 2, 3].map(&:odd?.to_proc) [true, false, true]