(call/cc (lambda (cont) (cont 知見)))

of 24/24
( call/cc ( lambda ( cont ) (cont 知見 ))) 2015 10 18 2 OUCC LT
  • date post

    08-Feb-2017
  • Category

    Engineering

  • view

    191
  • download

    5

Embed Size (px)

Transcript of (call/cc (lambda (cont) (cont 知見)))

  • ( c a l l / c c ( l a m b d a ( c o n t ) ( c o n t ) ) )

    2 0 1 51 01 8 2 O U C C LT

  • wier: @susisu2413

    GitHub: susisu

    Scheme

  • "continuationthe rest of the programprocedure"

    - Wikipedia https://ja.wikipedia.org/wiki/%E7%B6%99%E7%B6%9A

    https://ja.wikipedia.org/wiki/%E7%B6%99%E7%B6%9A

  • S

    (+ 1 2)

  • 2

    (+ 1 (...))

  • (lambda (x) (NEXT (+ 1 x) ))

    NEXT

  • c a l l / c c

    call-with-current-continuation

    ,

    , ,

  • (+ 1 2)

  • 2 c a l l / c c

    (+ 1 (call/cc (lambda (cont) (cont 2)) ))

  • c a l l / c c ( )

    (+ 1 (...))

  • (lambda (x) (NEXT (+ 1 x) ))

  • (+ 1 ( (lambda (cont) (cont 2)) (lambda (x) (NEXT ( (+ 1 x) ))) ))

  • (+ 1 (NEXT (+ 1 2) ))

  • 3

  • (break)

    (throw)

    (yield)

    return, goto, etc.

  • https://github.com/susisu/js-sandbox/blob/master/continuation/src/v2.js

    AST in JavaScript

    LT

    http://susisu.hatenablog.com/entry/2015/07/12/142250

    Scheme

    https://github.com/susisu/js-sandbox/blob/master/continuation/src/v2.jshttp://susisu.hatenablog.com/entry/2015/07/12/142250

  • ( )

    Expr

    eval : Expr Res

    Res = Ok Val

    | Cont Val (Res Res)

    | Next Val

  • e = (e1 : Expr, e2 : Expr, ..., eN : Expr) : Expr

    r = eval e, ri = eval ei

    ri = Ok v ei+1 , i = N r = Ok v

    Cont f c r = Cont f ((x eval ([r1, ..., ri-1,] x, ei+1, ..., eN)) c)

    Next v r = Next v

  • Ok v Next v

    eval (call/cc f) = Cont f (x x)

    (call/cc f) Cont f c

    c (f c) ()

  • ?

  • D E M O