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

Re: expansion of LETREC

Off-hand it seems odd that one can't write LETREC in Scheme -- the
problem, of course, is that special forms are usually equated with
macros, which have limited transformation capabilities.  One CAN define
the semantics of LETREC in Scheme by the following transformation:

    Let xi' be like xi except that all (free) occurrences of vi are
    replaced with (force vi); similarly for body'.  Then:

    (letrec ((v1 x1) (v2 x2) ...) body)  ==>
    (let ((v1 (delay (error ...))) (v2 (delay (error ...))) ...)
      (let ((temp1 x1') (temp2 x2') ...) ;unspecified evaluation order
        (set! v1 (delay temp1))          ;tempi don't occur free in body
        (set! v2 (delay temp2))

Compare this with your:

    (let ((v1 <unspecified>) (v2 <unspecified>) ...)
      (let ((temp1 x1) (temp2 x2) ...)    ;unspecified evaluation order
        (set! v1 temp1)                   ;tempi don't occur free in body
        (set! v2 temp2)
I haven't thought about this in detail, like how it interacts with
CALL-WITH-CURRENT-CONTINUATION, but off-hand it seems to avoid the
proliferation of primitive special forms (your solution 1) or primitive
procedures (your solutions 2-5) yet is precise in the semantics (I think).