u/ron_pro

▲ 3 r/scheme

So I'm just learning Scheme now. I learned Lisp many years ago, but now I want to know scheme specifically. Right now I'm learning about continuations. After trying to figure this out on my own I realized that half my problem (with being slow at understanding what's going on) is this weird method of calling call/cc to get the continuation. So, I came up with a simple function that I think does what one generally does when calling call/cc and instantly I understood what continuations are. But I wonder if my 'fix' to the code is legitimate. Here's the function I wrote:

(define /cc (lambda ()

(call/cc

(lambda (k)

k))))

So, it just reverses the odd syntaxy for call/cc to a function /cc which just returns a current continuation. Which I can save (define k (/cc)) and invoke later to jump back to this spot with restored context (stack and environment).

Is it wrong to do it this way? Do I miss out on anything if I choose to use this instead of call/cc directly? Any other things I should be aware of?

Thanks for any help.

reddit.com
u/ron_pro — 12 days ago