ãã®è¨äºã¯ Functional Ikamusume Advent Calendar jp 2010 ã«ãã£ã¦ä¾µç¥ãããã§ã²ã½ã
ä»å㯠Ruby ãä¾µç¥ããã§ã²ã½ãã¾ã㯠gem ãã¤ã³ã¹ãã¼ã«ããã§ã²ã½ã
$ gem install ikamusume
Hello, world ã§ã²ã½ã
# coding: utf-8 # ruby examples/hello.ikamusume ã§å®è¡ããã§ã²ã½ # æªã ã« 1.8 ã使ã£ã¦ãæããªã人é¡ã¯ -Ku ãä»ããã°ããããããªã¤ã«ï¼ require "ikamusume" "Hello, world!\n" <= ã¤ã«å¨! "H" <= "e" <= "l" <= "l" <= "o" <= "," <= " " <= "w" <= "o" <= "r" <= "l" <= "d" <= "!" <= "\n" <= ã¤ã«å¨!
$ ruby examples/hello.ikamusume Hello, world! Hello, world!
次ã¯åè§ãã²ã½ã²ã½è¨ãã§ã²ã½ã
# coding: utf-8 # based on Square.unl # see http://www.madore.org/~david/programs/unlambda/ in detail require "ikamusume" "\n" <= (ä¾µç¥! <= ã¤ã«å¨! <= (ã²ã½ <= (ä¾µç¥! <= (ä¾µç¥! <= (ã²ã½ <= ã²ã½) <= (ä¾µç¥! <= ã¤ã«å¨!)) <= (ä¾µç¥! <= (ä¾µç¥! <= ã¤ã«å¨! <= (ã²ã½ <= (ä¾µç¥! <= (ã²ã½ <= (ä¾µç¥! <= (ã²ã½ <= (ä¾µç¥! <= ã²ã½ <= (ä¾µç¥! <= "\n" <= (ã²ã½ <= "ã²ã½")))))) <= ã¤ã«å¨!))) <= "\n"))) <= (ä¾µç¥! <= ã¤ã«å¨! <= (ä¾µç¥! <= ã¤ã«å¨! <= (ä¾µç¥! <= ã¤ã«å¨! <= (ä¾µç¥! <= ã¤ã«å¨! <= (ä¾µç¥! <= ã¤ã«å¨! <= (ä¾µç¥! <= ã¤ã«å¨! <= (ã²ã½ <= (ã²ã½ <= ã¤ã«å¨!)))))))))
$ ruby examples/square.ikamusume ã²ã½ ã²ã½ã²ã½ ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½
æå¾ã«ãã£ããããã®æ°ã ãã²ã½ã¨ããã§ã²ã½ã
# coding: utf-8 # based on example probram in Unlambda document # see http://www.madore.org/~david/programs/unlambda/ in detail require "ikamusume" ä¾µç¥! <= (ä¾µç¥! <= (ä¾µç¥! <= ã¤ã«å¨! <= ã¤ã«å¨!) <= (ã²ã½ <= ã¤ã«å¨!)) <= (ã²ã½ <= "ã²ã½") <= (ä¾µç¥! <= (ä¾µç¥! <= (ã²ã½ <= ä¾µç¥!) <= (ä¾µç¥! <= (ã²ã½ <= (ä¾µç¥! <= (ã²ã½ <= ä¾µç¥!))) <= (ä¾µç¥! <= (ä¾µç¥! <= (ã²ã½ <= ä¾µç¥!) <= (ä¾µç¥! <= (ã²ã½ <= (ä¾µç¥! <= (ã²ã½ <= "\n"))) <= (ä¾µç¥! <= (ã²ã½ <= (ä¾µç¥! <= ã¤ã«å¨!)) <= ã²ã½))) <= ã²ã½))) <= (ã²ã½ <= (ä¾µç¥! <= (ã²ã½ <= ä¾µç¥!) <= ã²ã½)))
$ ruby examples/fib.ikamusume ã²ã½ ã²ã½ ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ã²ã½ (ç¥)
ãã¾ãã« Unlambda ãä¾µç¥ãããã§ã¯ãªã¤ã«ã
require "ikamusume" puts unlambda_to_ikamusume! <<END ```s``s``sii`ki `k.*``s``s`ks ``s`k`s`ks``s``s`ks``s`k`s`kr``s`k`sikk `k``s`ksk END
解説ã§ã²ã½
ãä¾µç¥!ãã S ã³ã³ããã¼ã¿ããã²ã½ãã K ã³ã³ããã¼ã¿ããã¤ã«å¨!ãã I ã³ã³ããã¼ã¿ã§ããA <= Bã㯠application ãªã®ã§ã²ã½ã"æåå" <= A ã¯ãæååãã表示ã㦠A ãè¿ãã§ã²ã½ãç´°ãããã¨ã¯ã½ã¼ã¹ãè¦ãã§ã²ã½ã
詳ãããã¨ã¯ SKI コンビネータã Unlambda ã調ã¹ãã°ããããããªã¤ã«ï¼