$30 off During Our Annual Pro Sale. View Details »

NDS_36_RubyCurry

 NDS_36_RubyCurry

NDS#36 の言語セッションでしゃべった内容です。

kasacchiful

March 15, 2014
Tweet

More Decks by kasacchiful

Other Decks in Programming

Transcript

  1. JaSST’14 Niigata • ೔࣌ɿ2014೥4݄11೔ʢۚʣ10:00 ʙ 16:50 • ձ৔ɿग࡝ϝοηɹதձٞࣨ302B • جௐߨԋɿদඌ୩

    ప ࢯʮςετͷલʹνʔϜͷݱ৔ྗΛσόοά!!ɹɹ ʙݱ৔ྗΛܭଌ͠ɼ߹ཧతͳຏ͖ํΛֶͿʙʯ • ϫʔΫγϣοϓɿ૿ా ྱࢠ ࢯʮݱ৔ྗͱνʔϜϏϧσΟϯάɹɹɹɹ ʙνʔϜΛ࡞ͬͯɼຏ͍͍ͯͨ͘Ίʹʙʯ • ਃࠐక੾ɿ2014೥4݄4೔ʢۚʣ • Webɿhttp://jasst.jp/symposium/jasst14niigata.html
  2. Ruby ͷ Curry hoge = -> (x,y,z) { x +

    y * z } ## hoge = lambda {|x,y,z| x + y * z} ͱಉ͡ curry_hoge = hoge.curry ! hoge.call(1,2,3) #=> 7 hoge[2,3,4] #=> 14 ! curry_hoge.call(1).call(2).call(3) #=> 7 curry_hoge[2][3][4] #=> 14
  3. Ruby ͷ Curry hoge = ->(x,y,z) { x + y

    * z } curry_hoge = hoge.curry ## curry_hoge = ->(x) { ->(y) { ->(z) { x + y * z }}} ͱಉ͡ ! ɾProc#curry ͸ Ruby 1.9 ͔Β࢖͑Δ
  4. Wikipedia ͷྫΛ Ruby Ͱ div = ->(x,y) { x /

    y } ## currying cdiv = div.curry #=> ->(x) {->(y) { x/ y }} ## partial application inv = cdiv[1.0] #=> ->(y) { 1.0 / y } inv[3] #=> 0.3333333333333333 inv[10] #=> 0.1
  5. ଞݴޠͰͷ Curry • ୈҰڃؔ਺Λѻ͑ΔݴޠͰ͋Ε͹ɺΧϦʔԽΛ࣮ࢪ͢Δ ؔ਺Λ࣮૷Մೳɻ • ྫɿLISP, Scheme, F#, Scala,

    Erlang, Eiffel, Perl, Python, Rݴޠ, Sݴޠ, JavaScript • ϥΠϒϥϦͰɺΧϦʔԽؔ਺Λ࢖͑Δݴޠ΋͋Δ • Groovy ͷ curry ͸෦෼ద༻ͳͷͰ஫ҙ ग़యɿʮΧϦʔԽ - Wikipediaʯ http://ja.wikipedia.org/wiki/%E3%82%AB%E3%83%AA%E3%83%BC%E5%8C%96