ふつける


Ikarus Scheme is a free optimizing incremental native-code compiler
for Scheme as specified in the Revised^6 Report on the Algorithmic
Language Scheme.

Ikarus Scheme is an optimizing compiler, so your Scheme code will
run fast without the need to port hot spots to C "for performance".
With an incremental compiler, you don't need a separate compilation
step to make your program run fast. The best part is that the
compiler itself is fast, capable of compiling thousands of lines
of code per second.

Finally, Ikarus Scheme is an R6RS compiler. R6RS libraries, scripts,
record types, condition system, exception handling, unicode strings,
bytevectors, hashtable, and enumerations are among the supported
features.

WWW:    http://www.ikarus-scheme.org/

今朝のcvsupで上記のようなものが入ってきた。昔shiroさんが言っていた
ものだ。早速試してみようと思ったら、
Ikarus Scheme cannot run on your computer because
your CPU does not support the SSE2 instruction set.
と言われてしまったわい。いいかげんに古いマシンは捨てろって事だね。
ひょっとして、作者さんは某Intelから販促費を貰っていませんか?
私の場合は、これぐらいで留めておくのが良さそうだ。

最近は、Firefoxを立ち上げるのも事実上苦痛になっているため、w3mを
使っていたりして、emacs上でもw3mしたいよねと、www/emacs-w3mも入れて
みたんだ。ただ、w3mで作ったbookmarkの参照方法が分からなくて、ちょっと
放り出してました。
数日前に、何の気なしに、M-x w3m TAB したら、w3m-bookmark-view が出て
きた。ひょっとしてと思って、こやつを指定したら、目出度くbookmarkを
参照してくれた。何事もやってみるもんだねぇ。

閉話休題
昔の本を引っ張り出して読んでいる。いわゆる、ふつける本と向井さんの
サイン入り、入門Haskellだったりだ。
ふつうのHaskellプログラミングは、青木さんのページでソースが公開されて
いるので、ちょっと試してみるにはうってつけだ。
Haskellで書かれたWikiであるLazyLinesが直ぐに動くかと思ったら、ちょいと
はまってしまった。

WindowsXPでは、何故かserverがレスポンスを返さないため、LazyLinesを拝めず。
Debianでは、コンパイル中に、Net.URIが見つからんエラーが発生。念力で
足りないものを推測。libghc6-net-devel だったかを追加インストールしてあげ
たから、動いてくれた。但し、めっちゃ遅いので、使うのをやめてしまった。
残るは、FreeBSDだか、こやつもコンパイルエラーが発生。
strftimeのパターンマッチがまずいと言う。Debianではちゃんと動いているのだ
から、ghcのRev違いによるものだろうか?
formatTimeを使っている所を、showに変えてナチュラルな日付表示にして、急場
を凌ぐ事にした。
残るは、serverであるが、Linux専用ときている。何か手はないかと思っていたら
さすが青木さん! server.rbなんてのが目に入ってきたので、ruby server.rb
したら、WEBrickが立ち上がってくれて、無事に動きましたとさ。
後は、おいおいソースを鑑賞する事にしましょう。

で、これで終わってしまっては、何にもならないので、ちょいとお勉強。
てこづった、System.Timeがどうなっているかと調べ始めました。
getClockTimeで、日時が取れる事は分かったので、これを使えば、プログラムの
実行時間が求められるよね。
プログラミングを始めたはいいのですが、

Prelude> :m +Time
Prelude Time> let now = getClockTime
Loading package old-locale-1.0.0.0 ... linking ... done.
Loading package old-time-1.0.0.0 ... linking ... done.
Prelude Time> now
Thu Apr 30 11:42:51 JST 2009
Prelude Time> :t now
now :: IO ClockTime

と言う事で、Haskell流に言うと、不純?なデータなんです。この不純な
データは特殊な環境に置いておかないと、扱えません。
何か例がないかと思って探してみたら、

[sakae@fb ~/HS]$ cat time.hs
--引数に入れた外部ファイルの実行速度を測るぜ!
module Main where
import System
import System.Process
import Time
main = do
    args <- getArgs
    start <- getClockTime
    wait $ head args
    end <- getClockTime
    putStrLn $ show $ diffClockTimes end start

wait :: String -> IO ExitCode
wait = (>>= waitForProcess) . runCommand

[sakae@fb ~/HS]$ runghc time.hs pwd
/home/sakae/HS
TimeDiff {tdYear = 0, tdMonth = 0, tdDay = 0, tdHour = 0, tdMin = 0, tdSec = 0, tdPicosec = 15470000000}

ピコ秒単位で、表示されました。
ちょっと現実離れしてるので、改造します。
System.CPUTime を取り込んでおいて、getClockTime を、getCPUTimeに変更
出力部分を、
putStrLn $ show $ fromInteger (end - start) / fromInteger (10^12)
に変更。

[sakae@fb ~/HS]$ runghc tnew.hs pwd
/home/sakae/HS
7.023e-3

こんな事をしながら、勉強してくんですが、手頃な実験をやろうとすると
randomが欲しくなる。やはり、System.Randomを読んでみたけど、難しい。
何か例はないかと探してみたら、サイコロを振る例が見つかった。

import Random

rollDice :: IO Int
rollDice = getStdRandom (randomR (1,6))

いろいろと探しているうちに素晴らしいページに行き着いた。
Real World Haskell