2007-08-26から1日間の記事一覧

Rubyで自己書換えプログラムを作る。

なんとなく。 % ruby -e 'ex = lambda{|e| puts e}; b = binding; STDIN.each{|l| ex.call(eval(l, b))}' 1 + 2 3 ex = lambda{|e| print "=> "; puts e} # ex update #<Proc:0xb7f40a58@-e:1> 1 + 2 => 3 ex = lambda{|e| print "=> "; puts e; print ": "} => #<Proc:0xb7f40760@-e:1> => nil : 1 + 2 =</proc:0xb7f40760@-e:1></proc:0xb7f40a58@-e:1>…

標準入力からgnuplot

忘れそうなのでメモ。 % cat plot.txt plot '-' w l 1 1 2 4 3 9 4 16 e % gnuplot -persist < plot.txt -persistでグラフウィンドウ表示 plot '-'でファイルの代わり。eまたはendで終了。 プログラムから利用するときに便利です。 Rubyでgnuplot 2乗のグラ…

Rubyで電卓作ってみた。

前回のエントリでコマンドライン電卓dcを試したけど、Rubyワンライナの方が断然便利だった。 % ruby -e 'STDIN.each{|l| puts eval(l)}' 1 + 2 3残念ながらこのワンライナでは、 フォーマット指定が面倒 変数が使えない と、イマイチな所もあるので、書き直…