トップレベルに式を書く
と、マクロが勝手にmodule及びMainを用意して、その中に式を放り込んでくれます。
using System; def range (begin, end, step) { mutable n = begin; fun () { when (n >= end) throw InvalidOperationException (); def x = n; n += step; x; } } def times (n, func) { for (mutable i = 0; i < n; ++i) func (); } def gen = range (0, 30, 7); try { times (10, fun () { Console.WriteLine (gen ()) }); } catch { | _ is InvalidOperationException => Console.WriteLine ("Stop Iteration"); | _ => (); } /* 0 7 14 21 28 Stop Iteration */
ちょっとしたサンプル書くときに楽かも。しかし、classやmoduleキーワードを使うとコンパイルエラーになり(メソッド内でclass/moduleを定義することになるので)、エラーメッセージも分かりにくいので積極的には使わない方が良いでしょうね。