Skip to content

Comment on Continuations by example: Exceptions, time-traveling search, threads, and moreparent

Comments

I'm having an ADHD night and I had the same thought, except I haven't died yet. Felt like giving up three times already, but I did have a click moment after playing around with a scheme repl for a couple of minutes. I understand the first example of call/cc now!

  (display
    (call/cc (lambda (cc)
              (display "I got here.\n")
              (cc "This string was passed to the continuation.\n")
              (display "But not here.\n"))))
Edit: Tried playing around with mit-scheme, but it doesn't work with the ctrl-v'ing the examples. Chezscheme does work.

It seems that MIT-Scheme needs the cc function to be a function of 1 argument (the return value for the continuation)[0]

Changing it to the following should work:

  (let ((start #f))
    (if (not start)
      (call/cc (lambda (cc)
                 (set! start cc))))
  
    (display "Going to invoke (start)\n")
    
    (start #f))
[0] https://www.gnu.org/software/mit-scheme/documentation/stable...

For what it's worth, almost any time Matt writes about Scheme he's likely using Racket so it'd be worth trying that for his posts!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.