Upgrade to Pro — share decks privately, control downloads, hide ads and more …

:|┃ / tokyu rubykaigi 12

D9d0ceb387e3b6de5c4562af78e8a910?s=47 ujihisa
July 29, 2018

:|┃ / tokyu rubykaigi 12

A tech talk at Tokyu RubyKaigi 12, featuring how to implement musical repeat sign :|┃ in Ruby, using continuation (callcc) which is a killer feature of Ruby.

D9d0ceb387e3b6de5c4562af78e8a910?s=128

ujihisa

July 29, 2018
Tweet

Transcript

  1. :|┃ TokyuRubyKaigi12 2018-07-29 ujihisa

  2. :|| 反復記号

  3. require 'continuation' class String def |(x) x.() end end def

    ┃ -> { $c.call($c) } end class Proc def |(_) $c = callcc {|c| c } end end $c ||= callcc {|c| c }
  4. require 'さっきのやつ' puts 'before' %: :|┃ p 'after'

  5. require 'さっきのやつ' puts 'before' %: :|┃ p 'after'

  6. require 'さっきのやつ' puts 'before' (%: :).|(┃) p 'after'

  7. require 'continuation' class String def |(x) x.() end end def

    ┃ -> { $c.call($c) } end class Proc def |(_) $c = callcc {|c| c } end end $c ||= callcc {|c| c }
  8. require 'さっきのやつ' puts 'first' ┃|:"start\n".display puts 'before' %: :|┃ p

    'after'
  9. require 'さっきのやつ' puts 'first' ┃|:"start\n".display puts 'before' %: :|┃ p

    'after'
  10. require 'continuation' class String def |(x) x.() end end def

    ┃ -> { $c.call($c) } end class Proc def |(_) $c = callcc {|c| c } end end $c ||= callcc {|c| c }
  11. :|┃ continuation便利 毎日使おう