[plt-scheme] Behind the scenes of letrec
Yes, indeed, but that is a choice.
To perform some program transformation techniques (for example lambda
lifting) it is "easier" to have explicit local definitions and simply
eliminate letrec expressions.
Marco
On Wed, Feb 27, 2008 at 10:47 PM, <benderjg2 at aol.com> wrote:
> Put another way... Local defines are often transformed into a letrec. At least that's my impression.
>
> Sent via BlackBerry by AT&T
>
>
> -----Original Message-----
> From: John Clements <clements at brinckerhoff.org>
>
> Date: Wed, 27 Feb 2008 19:42:27
> To:"Marco Morazan" <morazanm at gmail.com>
> Cc:pltscheme <plt-scheme at list.cs.brown.edu>
> Subject: Re: [plt-scheme] Behind the scenes of letrec
>
>
>
> On Feb 27, 2008, at 6:00 PM, Marco Morazan wrote:
>
> > Dear All,
> >
> > I am considering different alternatives for implementing letrec. As an
> > example consider the following:
> >
> > (letrec ((a (lambda (b) (* 2 b)))
> > (b (lambda (c) (a c)))
> > (c (lambda (q) (b q))))
> > (c 5))
> >
> > We can implement it by transforming letrec into let and use
> > assignment:
> >
> > (let ((a '())
> > (b '())
> > (c '()))
> > (let ((x (lambda (b) (* 2 b)))
> > (y (lambda (c) (a c)))
> > (z (lambda (q) (b q))))
> > (set! a x)
> > (set! b y)
> > (set! c z))
> > (c 5))
> >
> > I am aware that Dybvig et. al. proposed a more sophisticated
> > transformation to let with assignments.
> >
> > Alternatively, we could transform the letrec into an application
> > expression and create a new local function (i.e. within the same scope
> > of the letrec expression) such as:
> >
> > new local function:
> >
> > (define (new)
> > (define a (lambda (b) (* 2 b)))
> > (define b (lambda (c) (a c)))
> > (define c (lambda (q) (b q)))
> > (c 5))
> >
> > new application expression:
> >
> > (new)
> >
> >> From a purist's perspective, the latter is attractive given the lack
> > of assignment. What are the reasons for preferring the former
> > transformation?
>
> How are you planning to implement the local defines?
>
> John
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>