[Bese-devel] CPS + loop
ml13 at onlinehome.de
ml13 at onlinehome.de
Tue Dec 27 13:38:20 UTC 2005
Hi,
I was toying around with simple choose and fail, which was basically
working fine, but when I introduced loop, things broke...
I'd be happy about any comments on the code snippet below,
specifically I am wondering, whether this loop thing is to be
considered a bug of the CPS transformer or a problem in my code.
Cheers,
Kilian Sprotte
(setq *call/cc-returns* t)
;; => T
(defvar ks nil "continuation stack")
;; => KS
(defun/cc choose123 ()
(block nil
(let/cc k (push k ks) (return 1))
(let/cc k (push k ks) (return 2))
3))
;; => CHOOSE123
(defun/cc fail ()
(if ks
(kall (pop ks))
:fail))
;; => FAIL
(defun next ()
(with-call/cc (fail)))
;; => NEXT
(with-call/cc
(setq ks nil)
(let ((l (list (choose123) (choose123) (choose123))))
(if (not (= 4 (apply #'+ l)))
(fail)
l)))
;; => (1 1 2)
(next)
;; => (1 2 1)
(next)
;; => (2 1 1)
(next)
;; => :FAIL
;; so far so good...
;; let's try with loop
(with-call/cc
(setq ks nil)
(let ((l (loop repeat 3 collect (choose123))))
(if (not (= 4 (apply #'+ l)))
(fail)
l)))
;; => (1 1 2)
(next)
;; => (1 3)
(next)
;; => :FAIL
More information about the bese-devel
mailing list