[r6rs-discuss] A suggestion about LETREC

From: Joe Marshall <jmarshall>
Date: Wed Mar 28 17:25:46 2007

On 3/28/07, Abdulaziz Ghuloum <aghuloum_at_cs.indiana.edu> wrote:
>
> On Mar 28, 2007, at 12:51 PM, Joe Marshall wrote:
>
> > Since we're discussing the semantics of LETREC, I've always thought
> > it was
> > a wart in the language to specify LETREC in terms of SET! It would
> > be nice
> > if implementations were permitted (but not required) to implement
> > LETREC
> > in terms of a fixed-point operator as an alternative to SET!
>
> Do you mean that an implementation should be allowed to treat E1 as E2
> or E3 instead of E4?
>
> E1=
> (letrec ((fact (lambda (n) (if (zero? n) 1 (fact (- n 1))))))
> (fact 5))
>
> E2=
> (fix ((fact (lambda (n) (if (zero? n) 1 (fact (- n 1))))))
> (fact 5))
>
> E3=
> (let ([fact (Y (lambda (fact)
> (lambda (n) (if (zero? n) 1 (fact (- n 1))))))])
> (fact 5))
>
> E4=
> (let ((fact (unspecified)))
> (let ((t (lambda (n) (if (zero? n) 1 (fact (- n 1))))))
> (set! fact t))
> (fact 5))

Yes.


> > One advantage of this is that it would be much easier to create a
> > purely
> > functional subset of Scheme.
>
> How do you do the following functionally?
>
> (letrec ([f (g (lambda () f))])
> f)

With a lot of rewriting so that f can take a thunked version of itself
as an argument.

-- 
~jrm
Received on Wed Mar 28 2007 - 17:25:05 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC