Reputation: 10314
I'm trying to implement a return
function in Scheme R6RS. I want something such that:
(lambda ()
(do-some-job-before)
(return some-value)
(do-some-job-after))
executes (do-some-job-before)
, do not execute (do-some-job-after)
and the final value of the lambda function in some-value
.
I guess I have to use a continuation. I tried:
(define return #f)
(call/cc (lambda (k)
(set! return k)))
but it does not work; e.g
(+ 2 (return 3)) ; -> 3 (and not 5 as I expected)
How can i do this?
Upvotes: 4
Views: 96