Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why my DEFMACRO fails?

Name: Anonymous 2012-02-27 10:19


(defmacro call/cc (f)
  (let ((l (gensym))
        (r (gensym))
        (v (gensym)))
   `(let ((,r nil))
      (tagbody (setf ,r (funcall ,f (lambda (,v)
                                   (setf ,r ,v)
                                   (go ,l))))
                ,l)
      ,r)))


It works in some cases but fails on (let ((k nil)) (call/cc (lambda (c) (setf k c))) (print 123) (funcall k nil))

How do I fix it?

Name: Anonymous 2012-02-28 10:11

>>1-3
If you want call/cc in CL you either need to write a code walker which transforms the code using Continuation Passing Style or by using some low-level heap-copying tricks - it's also how Scheme implementations do it. There's a portable library that does it in the first way and there's some implementation forks/extensions that do it in the second way.
Doing it using a tagbody like that won't work as it does something similar, but different from the real call/cc.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List