Scala をコマンドラインで使う - 2
色々事情があって日が空いてしまいました.
ということで,明日はScala座です.
あんまり関係無いかもですが,続きです.
$ time (scall ~/.zshrc > /dev/null) (; scall ~/.zshrc > /dev/null; ) 1.87s user 0.18s system 39% cpu 5.128 total $ time (perl -pe1 ~/.zshrc > /dev/null) (; perl -pe1 ~/.zshrc > /dev/null; ) 0.00s user 0.00s system 45% cpu 0.009 total $ time (cat ~/.zshrc > /dev/null) (; cat ~/.zshrc > /dev/null; ) 0.00s user 0.00s system 47% cpu 0.005 total
おっそい.
そこで,コンパイルですよ.
とあいえ,引数で String をもらってる訳で,
姉さん,事件です.
まぁ,普通に Eval ですよね.
という訳で書いてみた.
eval するには scala.tools.nsc.Interpreter を使えばいいらしいよ.
後述のエイリアスをかけて,scall で呼び出せるようにする.
# cat 的な $ scall ~/.zshrc | diff - ~/.zshrc
とりあえず,Zsh で補完できるようにする.
$ scall -<TAB> option -B -- Specify expression to run on begin of program -E -- Specify expression to run on end of program -e -- Specify expression to run with each line -h -- Show message and exit
よーし.パパ速度測っちゃうぞー.
$ time (scall ~/.zshrc > /dev/null) (; scala-2.8 -deprecation -cp com.myexample.Scall ~/.zshrc > /dev/null; ) 13.23s user 0.51s system 102% cpu 13.411 total
あり!?
ご参考
以下補足
ということで,本来コマンドラインで書くのは長いのでエイリアスをかけた.
普通ですね.で読み込みする.と
$ source scall.zsh