[Openmcl-devel] Delay / force doesn't work
Pascal Costanza
pc at p-cos.net
Thu Nov 30 12:03:28 PST 2006
Hi,
Here is an implementation of Scheme's delay/force in Common Lisp
together with a test case, modeled after the example implementations
in R5RS - see http://www.schemers.org/Documents/Standards/R5RS/HTML/
r5rs-Z-H-9.html#%_idx_562
When I run this code in OpenMCL 1.0 (on Mac OS X), I get the
following error:
> Error in process listener(1): Error reporting error
> While executing: CCL::FUNCALL-WITH-ERROR-REENTRY-DETECTION
> Type :POP to abort.
IMHO, this shouldn't happen. The code below works correctly in
Allegro, clisp, cmu, ecl and LispWorks, but not on OpenMCL, MCL and
SBCL.
(defclass promise ()
((value :accessor promise-value)
(thunk :initarg :thunk)))
(defmethod slot-unbound (class (instance promise) (slot (eql 'value)))
(declare (ignore class))
(let ((x (funcall (slot-value instance 'thunk))))
(if (slot-boundp instance 'value)
(promise-value instance)
(setf (promise-value instance) x))))
(defmacro delay (&body body)
`(make-instance 'promise :thunk (lambda () , at body)))
(defgeneric force (value)
(:method (value) value)
(:method ((value promise))
(promise-value value)))
(defvar *count* 0)
(defvar *x* 5)
(defvar *p*
(delay (incf *count*)
(if (> *count* *x*)
*count*
(force *p*))))
(assert (typep *p* 'promise))
(assert (= (force *p*) 6))
(assert (typep *p* 'promise))
(setf *x* 10)
(assert (= (force *p*) 6))
(print :done)
--
Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium
More information about the Openmcl-devel
mailing list