【激突】関数型言語 VS オブジェクト指向言語2at TECH【激突】関数型言語 VS オブジェクト指向言語2 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト496:デフォルトの名無しさん 12/04/18 13:31:40.56 スレタイに惹かれて開いたけどゴミスレだった・・・ 497:デフォルトの名無しさん 12/04/19 02:49:08.33 $t = sub { my $f = shift; sub { my $x = shift; $f->($f->($x)) } }; $rst = $t->($t)->($t)->($t)->( sub{ my $x = shift; $x + 1 })->(0); print $rst, "\n"; 498:デフォルトの名無しさん 12/04/19 09:02:56.87 同じくRubyも。 ケチがついた、オープンクラス、メソッドチェーン、リフレクションは無しで require 'test/unit' def fb(x, cnd, msg) th = Thread.current x.kind_of?(Integer) ? (th[:m] = n = x; s = "") : (n = th[:m]; s = x) cnd[n] ? s + msg : !s.empty? ? s : n end def fizz(n); fb(n, proc{ |n| n%3==0 }, "Fizz") end def buzz(n); fb(n, proc{ |n| n%5==0 }, "Buzz") end def gizz(n); fb(n, proc{ |n| n%7==0}, "Gizz") end class FizzBuzzQuizTest < Test::Unit::TestCase def test_fbq assert_equal( fizz(1), 1 ) assert_equal( fizz(3), "Fizz" ) assert_equal( buzz(fizz(1)), 1 ) assert_equal( buzz(fizz(3)), "Fizz" ) assert_equal( buzz(fizz(5)), "Buzz" ) assert_equal( buzz(fizz(15)), "FizzBuzz" ) assert_equal( gizz(buzz(fizz(105))), "FizzBuzzGizz" ) assert_equal( buzz(gizz(fizz(105))), "FizzGizzBuzz" ) end end 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch