Here's how to use call / cc to build return yourself.
(define (example x) (call/cc (lambda (return) (when (< x 0) (return
Some circuits define a macro called let / cc that lets you throw off some lambda noise:
(define (example x) (let/cc return (when (< x 0) (return
Of course, if your scheme does not allow it, let / cc be trivial to write.
This works because call / cc saves the point at which it was called as a continuation. It passes this continuation to its function argument. When a function calls this continuation, Scheme discards any call stack it has created so far and continues from the end of the / cc call. Of course, if a function never calls a continuation, then it just returns normally.
The continuations do not get truly intelligent until you start returning them from this function or maybe save them in the global data structure and call them later. Otherwise, they are similar to any structured-goto language expressions (while / for / break / return / continue / exceptions / conditions).
I don’t know what your complete code looks like, but it might be better to go with cond and decompose complex checks into separate functions. The need for return and let* usually a symptom of overly peremptory code. However, the call / cc method should now work with your code.
source share