[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
...sorry, the body of my previous message was delayed. It follows:
PROPOSAL FOR A NEW PREDICATE:
(DELAYED? <object>) ==> #T iff <object> is an unforced PROMISE
created via the DELAY procedure.
Insofar as it is possible to create a PROMISE (using DELAY), it
is desireable to detect if an object is in fact an unforced PROMISE.
To point, I find it occasionally desirable to check if a particular
PROMISE has ever been FORCEd soas to glean some information about the
dynamic behavior of a piece of code (such as, ``has this node in a tree
ever been visited (FORCEd)?''). To my knowledge, PROMISEs are the only
instance of a data-type in Scheme that may be created but not detected.
This makes them somewhat less than first-class in my mind.
SAMPLE IMPLEMENTATION: -- based on RRRS p.27
(delay <expression>) --> (make-promise (lambda () <expression>))
(let ((already-run? #F) (result #F))
(lambda (message) ; Add a message parameter
(case message ; Dispatch on message
((:FORCE) (cond ((not already-run?) ; Old code for FORCE
(set! result (proc))
(set! already-run? #T) ))
((:DELAYED?) (not already-run?)) )))))) ; Expose the toggle
(lambda (object) (object ':FORCE)) ))
(lambda (object) (object ':DELAYED?)) ))
Noting that some implementations may chose to make PROMISEs operationally
indistinguishable from their FORCEd value (e.g. implicit forcing), DELAYED?
may have to be a special form soas NOT to implicitly FORCE its argument.
Finally, I was very careful NOT to propose a predicate PROMISE?, noting
that some implementations may opt to make FORCE actually alter its argument
soas to henceforth be replaced (in the store) by the computed value. I
was likewise careful not to request (FORCED? <object>) which in some
implementations would NOT neccessarily be the logical inverse of
DELAYED? (e.g. may always return #F in implementations that modify the
store as noted above).