[racket] internal define

From: Jos Koot (jos.koot at gmail.com)
Date: Thu Dec 27 08:44:18 EST 2012

Some years ago I had a discussion with Eli Barzilay about a different
approach to letrec. The idea was to evaluate the expressions of the bindings
automatically in appropriate order. As an example:

(special-letrec
 ((a (+ b 2))
  (b (* c 3))
  (c 4))
 (list a b c))

would be evaluated in the following order:

(letrec
 ((c 4)
  (b (* c 3))
  (a (+ b 2)))
 (list (a b c))

The special letrec recognizes circular dependencies as in:

(special-letrec
 ((a (+ b 1))
  (b (+ a 1)))
 (list a b)) -> error: circular dependency in special letrec bindings.

Unfortunately I can't find the source code at this moment.

Jos

-----Original Message-----
From: users-bounces at racket-lang.org [mailto:users-bounces at racket-lang.org]
On Behalf Of Matthias Felleisen
Sent: jueves, 27 de diciembre de 2012 3:53
To: J. Ian Johnson
Cc: Dmitry Pavlov; users at racket-lang.org
Subject: Re: [racket] internal define


I added a warning to the style guide. 


On Nov 30, 2012, at 12:12 PM, J. Ian Johnson wrote:

> define does not have the same binding structure as let, much to my and
many other people's lament.
> Within a tree of begin forms (and the implicit begin in a function body),
there is a definition context that defines a new scope. Because you have a
(define x 2) in this context, x starts bound to #<undefined> and once it is
set by passing the define form, it is 2. This is the infamous behavior of
letrec*.
> 
> Thus, the x passed to test was shadowed immediately entering the body and
that is why your first reference is not as you expected. I would much rather
a let-like binding structure for something similar to define, say define* or
ilet (inline-let) or something.
> 
> You'll just have to use a different identifier for now.
> -Ian
> ----- Original Message -----
> From: "Dmitry Pavlov" <dpavlov at ipa.nw.ru>
> To: users at racket-lang.org
> Sent: Friday, November 30, 2012 12:03:12 PM GMT -05:00 US/Canada Eastern
> Subject: [racket] internal define
> 
> Hello,
> 
> I have been forcing myself to use (define) over (let),
> following the guide:
>
http://www.ccs.neu.edu/home/matthias/Style/style/Choosing_the_Right_Construc
t.html#(part._.Definitions)
> 
> So I have come across this strange behavior:
> 
> (define (test x)
>     (display x)
>     (define x 2)
>     (display x))
>> (test 1)
> #<undefined>2
> 
> while the analogous construct with (let) works as expected:
> 
> (define (test1 x)
>     (display x)
>     (let ((x 2))
>       (display x)))
>> (test1 1)
> 12
> 
> Is there a list of what one can do and what one can not
> do with internal define?
> 
> Best regards,
> 
> Dmitry
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users


____________________
  Racket Users list:
  http://lists.racket-lang.org/users


Posted on the users mailing list.