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

shift / reset

Avatar for tesso tesso
September 07, 2024
86

shift / reset

学生と社会人LT会 2024/09/07で発表したものです.
connpass : https://gijutsu-club.connpass.com/event/326674/

slide の内容を深堀したい人は, shift/resetで検索することをお勧めします.
特に下記のURLは参考になると思います.
- http://pllab.is.ocha.ac.jp/~asai/cw2011tutorial/main-j.pdf
- https://blog.miz-ar.info/2022/10/delimited-continuations/
- https://prg.is.titech.ac.jp/papers/pdf/flops2024-slides.pdf

Avatar for tesso

tesso

September 07, 2024

Transcript

  1. @tesso57 @tesso57 (てっそ) - 修士1年 - 研究 : 暗号理論 -

    ナンバーナイン 開発アルバイト - go, connect-go - FPSゲーマー - valorant - deadlock - 漫画好き
  2. @tesso57 実は同じ処理 try { throw "shift" } catch (error) {

    42 } reset ( fun () -> 1 + shift (fun k -> 42) ) ;;
  3. @tesso57 実は同じ処理 try { throw "shift" } catch (error) {

    42 } reset ( fun () -> 1 + shift (fun k -> 42) ) ;; わからん!
  4. @tesso57 これをわかった気になろう reset ( fun () -> 1 + shift

    (fun k -> 42) ) ;; reset: 1+ shift(k): 42 Python like に変換!
  5. @tesso57 普通 vs 継続 def inc(x): return x+1 print(inc(5)) 引用

    : CPS(継続渡しスタイル)のプログラミングに入門する (https://qiita.com/Kai101/items/eae3a00fcd1fc87e25fb) - 普通 - 6が出力
  6. @tesso57 普通 vs 継続 def inc_c(cont, x): cont(x+1) inc_c(print, 5)

    引用 : CPS(継続渡しスタイル)のプログラミングに入門する (https://qiita.com/Kai101/items/eae3a00fcd1fc87e25fb) - 継続 - inc_cが関数を受け取る!
  7. @tesso57 普通 vs 継続 def inc_c(cont, x): cont(x+1) inc_c(print, 5)

    引用 : CPS(継続渡しスタイル)のプログラミングに入門する (https://qiita.com/Kai101/items/eae3a00fcd1fc87e25fb) - 継続 - inc_cが関数を受け取る!
  8. @tesso57 普通 vs 継続 def inc(x): return x+1 print(inc(5)) def

    inc_c(cont, x): cont(x+1) inc_c(print, 5) 引用 : CPS(継続渡しスタイル)のプログラミングに入門する (https://qiita.com/Kai101/items/eae3a00fcd1fc87e25fb)
  9. @tesso57 普通 vs 継続 def inc(x): return x+1 print(inc(5)) def

    inc_c(cont, x): cont(x+1) inc_c(print, 5) 引用 : CPS(継続渡しスタイル)のプログラミングに入門する (https://qiita.com/Kai101/items/eae3a00fcd1fc87e25fb) 値に着目するのか,関数に着目するのか
  10. @tesso57 普通 vs 継続 def inc(x): return x+1 print(inc(5)) def

    inc_c(cont, x): cont(x+1) inc_c(print, 5) 引用 : CPS(継続渡しスタイル)のプログラミングに入門する (https://qiita.com/Kai101/items/eae3a00fcd1fc87e25fb) 関数に着目 → 処理を制御しやすい
  11. @tesso57 普通 vs 継続 - OnClick - setTimeout - 何かした後に、ある関数を発火する

    引用 : CPS(継続渡しスタイル)のプログラミングに入門する (https://qiita.com/Kai101/items/eae3a00fcd1fc87e25fb)
  12. @tesso57 限定継続 - shift : 計算を止める, kはshiftより前の計算 - reset :

    計算の範囲を決める reset: 1 + shift(k): 42 def k(x): 1 + x
  13. @tesso57 限定継続 - shift : 計算を止める, kはshiftより前の計算 - reset :

    計算の範囲を決める reset: 1 + shift(k): 42 def k(x): 1 + x 結果 : 42
  14. @tesso57 限定継続 - shift : 計算を止める, kはshiftより前の計算 - reset :

    計算の範囲を決める reset: 1 + shift(k): k(42) def k(x): 1 + x
  15. @tesso57 限定継続 - shift : 計算を止める, kはshiftより前の計算 - reset :

    計算の範囲を決める def k(x): 1 + x 結果 : 43 reset: 1 + shift(k): k(42)
  16. @tesso57 限定継続 - shift : 計算を止める, kはshiftより前の計算 - reset :

    計算の範囲を決める def k(x): 1 + x 結果 : 43 reset: 1 + shift(k): k(42) わかった気がする