[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

rec



I do not understand what all the confusion is about.
(rec alpha beta) is a special form which says evaluate
beta in an environment which associates the symbol alpha
with the meaning of beta.  This allows for such familiar
expressions (rec ! (lambda (n) (if (zero? n) 1 (* n (! (sub1 n)))))).
This builds a recursive object.  We can then associate another
symbol such as fact with this object.  Hence we may define fact as
(define fact (rec ! (lambda (n) (if (zero? n) 1 (* n (! (sub1 n))))))).
Now if that were all we could do with rec then I'd just as soon
use the applicative-order Y combinator and be done with it.
However,  because rec does not know that beta is a function
we can do fancier things.  For example, we can define lazy-cons
(just in the cdr) as

(lazy-cons a b) ==> (rec box
                         (cons a (lambda ()
                                    (let ([v b])
                                       (set-car! box (lambda () v))
                                       v)))

as a macro.  We have created a recursive box.  By the time we need
for the box identifier to be bound to the right piece it will be.
As far as I can tell this is what Will was trying to communicate but
it did not seem to be getting through.  For those who need reminding
the current marco for rec is

(rec alpha beta) ==> (let ([alpha '*]) (set! alpha beta) alpha)

Dan