diff options
| author | rtk0c <[email protected]> | 2024-11-18 23:49:51 -0800 |
|---|---|---|
| committer | rtk0c <[email protected]> | 2024-11-18 23:49:51 -0800 |
| commit | df9f9adedc3f0f4240f1f9e992a9d7ee8f04979b (patch) | |
| tree | 7dd6bfbb2e74d6e5b5d6c2660d04b66ceee97689 /content/blog | |
| parent | dba1ca6011843a47d03cf0d8625ae76a078040fe (diff) | |
[update] On continuations
Diffstat (limited to 'content/blog')
| -rw-r--r-- | content/blog/on-continuations.md | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/content/blog/on-continuations.md b/content/blog/on-continuations.md index bceb480..0c2e00f 100644 --- a/content/blog/on-continuations.md +++ b/content/blog/on-continuations.md @@ -12,14 +12,20 @@ draft: true ```scheme > (define cont '()) -> (+ 5 (* 12 (- 3 (* 3 7)) (call/cc (lambda (cc) (set! cont cc) 4)))) --859 -> (cont 1) --211 +> (+ (/ 12 2) + (* (+ 1 1) + (call/cc (lambda (cc) (set! cont cc) 4)))) +;; As if the (call/cc) part is just the constant 4 +;; (which we returned at in the lambda) +14 +> (cont 1) +;; As if we've evaluated the original expression, but with the (call/cc) part +;; replaced with the constant 1 +8 > (cont 2) --427 +10 > (cont 4) --859 +14 ``` which is indeed fascinating, though now _how_ it works and _why_ seem to hide themselves even further in the thick fog. [Calling them](http://community.schemewiki.org/?call-with-current-continuation-for-C-programmers) `setjmp`/`longjmp` makes perfect and clear sense, but at the cost of summoning a satan while blasting its putruid demonic breathe all over your face[^demonic-breathe]. What's more, everybody seems so inclined to mention this thing called "Continuation-Passing Style", which are mostly followed by some nonsensical rewriting of perfectly fine programs to pass [callbacks](https://stackoverflow.com/a/14022348) everywhere. |
