Re: [racket] internal definitions in r6rs

2010-09-19 Thread Jos Koot
Thanks Matthew,
Jos 

> -Original Message-
> From: Matthew Flatt [mailto:[email protected]] 
> Sent: 19 September 2010 03:54
> To: Jos Koot
> Cc: 'PLT-Scheme Mailing List'
> Subject: Re: [racket] internal definitions in r6rs
> 
> This is a bug in the R6RS binding for `define'. Your program 
> works as it should if you use
> 
>  (define a
>(lambda ()
>  (define (b) "who cares?")
>  (define c (b))
>  c))
> 
> or
> 
>  (define (a)
>(let ()
>  (define (b) "who cares?")
>  (define c (b))
>  c))
> 
> because the problem is specific to `define' with the function 
> shorthand.
> 
> I've pushed a repair.
> 
> At Sat, 18 Sep 2010 12:52:26 +0200, "Jos Koot" wrote:
> > Hi,
> >  
> > Section 11.3 of R6RS states: "An expanded  (see chapter 10) 
> > containing variable definitions can always be converted into an 
> > equivalent letrec* expression." The semantics of letrec* includes 
> > "each  is assigned in left-to-right order". This 
> I interpret 
> > as allowing an internal definition to refer to the value of 
> a previously defined variable. However:
> >  
> > #!r6rs
> >  
> > (import
> >  (rnrs base (6))
> >  (rnrs io simple (6)))
> >  
> > (define (a)
> >   (define (b) "who cares?")
> >   (define c (b))
> >   c)
> >  
> > (write (a))
> >  
> > Produces:
> >  
> > Welcome to DrRacket, version
> > 
> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
> > Language: r6rs; memory limit: 2000 MB.
> > . . procedure application: expected procedure, given: 
> # (no
> > arguments)
> >  
> > The code expands as follows. The hot spots is marked with an arrow.
> >  
> > (module anonymous-module r6rs
> >   (#%plain-module-begin
> >(#%require r6rs/private/prelims)
> >(#%require (lib "rnrs/base-6.rkt"))
> >(#%require (for-meta #f (lib "rnrs/base-6.rkt")))
> >(#%require (lib "rnrs/io/simple-6.rkt"))
> >(#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
> >(define-values (a)
> >  (#%plain-lambda
> >   ()
> >   (let-values (((b) undefined) ((c) undefined))
> > (let-values ; <== prohibits reference to value of 
> > previously defined var
> > (((newtemp)
> >   (#%plain-lambda () (letrec-values () (let-values () 
> > '"who
> > cares?"
> >  ((newtemp:19) (#%app b))) ; <==
> >   (set! b newtemp)
> >   (set! c newtemp:19)
> >   (let-values:20 () (let-values:21 () c))
> >(#%app write (#%app a
> > 
> > Is this a bug or do I misunderstand R6RS?
> > The following works correct:
> >  
> > #!r6rs
> >  
> > (import
> >  (rnrs base (6))
> >  (rnrs io simple (6)))
> >  
> > (define (a)
> >   (letrec*
> >((b (lambda () "who cares?"))
> > (c (b)))
> >c))
> >  
> > (write (a))
> >  
> > Thanks, Jos
> > _
> >   For list-related administrative tasks:
> >   http://lists.racket-lang.org/listinfo/users


_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] internal definitions in r6rs

2010-09-18 Thread Matthew Flatt
This is a bug in the R6RS binding for `define'. Your program works as
it should if you use

 (define a
   (lambda ()
 (define (b) "who cares?")
 (define c (b))
 c))

or

 (define (a)
   (let ()
 (define (b) "who cares?")
 (define c (b))
 c))

because the problem is specific to `define' with the function
shorthand.

I've pushed a repair.

At Sat, 18 Sep 2010 12:52:26 +0200, "Jos Koot" wrote:
> Hi,
>  
> Section 11.3 of R6RS states: "An expanded  (see chapter 10) containing
> variable definitions can always be converted into an equivalent letrec*
> expression." The semantics of letrec* includes "each  is assigned
> in left-to-right order". This I interpret as allowing an internal definition
> to refer to the value of a previously defined variable. However:
>  
> #!r6rs
>  
> (import
>  (rnrs base (6))
>  (rnrs io simple (6)))
>  
> (define (a)
>   (define (b) "who cares?")
>   (define c (b))
>   c)
>  
> (write (a))
>  
> Produces:
>  
> Welcome to DrRacket, version
> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
> Language: r6rs; memory limit: 2000 MB.
> . . procedure application: expected procedure, given: # (no
> arguments)
>  
> The code expands as follows. The hot spots is marked with an arrow.
>  
> (module anonymous-module r6rs
>   (#%plain-module-begin
>(#%require r6rs/private/prelims)
>(#%require (lib "rnrs/base-6.rkt"))
>(#%require (for-meta #f (lib "rnrs/base-6.rkt")))
>(#%require (lib "rnrs/io/simple-6.rkt"))
>(#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
>(define-values (a)
>  (#%plain-lambda
>   ()
>   (let-values (((b) undefined) ((c) undefined))
> (let-values ; <== prohibits reference to value of previously
> defined var
> (((newtemp)
>   (#%plain-lambda () (letrec-values () (let-values () '"who
> cares?"
>  ((newtemp:19) (#%app b))) ; <==
>   (set! b newtemp)
>   (set! c newtemp:19)
>   (let-values:20 () (let-values:21 () c))
>(#%app write (#%app a
> 
> Is this a bug or do I misunderstand R6RS?
> The following works correct:
>  
> #!r6rs
>  
> (import
>  (rnrs base (6))
>  (rnrs io simple (6)))
>  
> (define (a)
>   (letrec*
>((b (lambda () "who cares?"))
> (c (b)))
>c))
>  
> (write (a))
>  
> Thanks, Jos
> _
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] internal definitions in r6rs

2010-09-18 Thread Jos Koot
 
Thanks.
I do not often use rnrs, for I prefer racket. But sometimes people ask me
r6rs or even r5rs code. I have decided to send them racket code and let them
make the required mods themselvesw.
Thanks, Jos

> -Original Message-
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Robby Findler
> Sent: 19 September 2010 01:03
> To: Jos Koot
> Cc: PLT-Scheme Mailing List
> Subject: Re: [racket] internal definitions in r6rs
> 
> It has been a while but I believe the r6 formal model covers 
> this point.
> 
> Robby
> 
> On Saturday, September 18, 2010, Jos Koot 
>  wrote:
> >
> >
> >
> >
> >
> > Hi,
> >
> > Section 11.3
> > of R6RS states: "An expanded  (see chapter 10) containing 
> > variable definitions can always be converted into an equivalent 
> > letrec* expression." The semantics of letrec* includes "each 
> >  is assigned in left-to-right order". This I interpret as 
> > allowing an internal definition to refer to the value of a 
> previously defined variable.
> > However:
> >
> > #!r6rs
> >
> > (import
> >  (rnrs base (6))
> >  (rnrs io
> > simple (6)))
> >
> > (define
> > (a)
> >   (define (b) "who cares?")
> >   (define c (b))
> > c)
> >
> > (write
> > (a))
> >
> > Produces:
> >
> > Welcome to
> > DrRacket, version
> > 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a)
> > [3m].
> > Language: r6rs; memory limit: 2000 MB.
> > . . procedure application:
> > expected procedure, given: # (no arguments)
> >
> > The code
> > expands as follows. The hot spots is marked with an arrow.
> >
> > (module
> > anonymous-module r6rs
> >   (#%plain-module-begin
> >    (#%require
> > r6rs/private/prelims)
> >    (#%require (lib
> > "rnrs/base-6.rkt"))
> >    (#%require (for-meta #f (lib
> > "rnrs/base-6.rkt")))
> >    (#%require (lib
> > "rnrs/io/simple-6.rkt"))
> >    (#%require (for-meta #f (lib
> > "rnrs/io/simple-6.rkt")))
> >    (define-values
> > (a)
> > (#%plain-lambda
> > ()
> >   (let-values (((b) undefined) ((c)
> > undefined))
> >     (let-values ;
> > <== prohibits reference to value of previously defined var
> > (((newtemp)
> > (#%plain-lambda () (letrec-values () (let-values () '"who
> > cares?"
> > ((newtemp:19) (#%app b))) ;
> > <==
> >   (set! b
> > newtemp)
> >   (set! c
> > newtemp:19)
> > (let-values:20 () (let-values:21 () c))
> >    (#%app write (#%app
> > a
> >
> > Is this a bug or do I misunderstand
> > R6RS?
> > The
> > following works correct:
> >
> > #!r6rs
> >
> > (import
> >  (rnrs base
> > (6))
> >  (rnrs io simple (6)))
> >
> > (define (a)
> > (letrec*
> >    ((b (lambda () "who cares?"))
> >     (c
> > (b)))
> >    c))
> >
> > (write (a))
> >
> > Thanks,
> > Jos
> >
> >
> >


_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] internal definitions in r6rs

2010-09-18 Thread Robby Findler
It has been a while but I believe the r6 formal model covers this point.

Robby

On Saturday, September 18, 2010, Jos Koot  wrote:
>
>
>
>
>
> Hi,
>
> Section 11.3
> of R6RS states: "An expanded  (see chapter 10) containing variable
> definitions can always be converted into an equivalent letrec* expression." 
> The
> semantics of letrec* includes "each  is assigned in
> left-to-right order". This I interpret as allowing an internal definition to
> refer to the value of a previously defined variable.
> However:
>
> #!r6rs
>
> (import
>  (rnrs base (6))
>  (rnrs io
> simple (6)))
>
> (define
> (a)
>   (define (b) "who cares?")
>   (define c (b))
> c)
>
> (write
> (a))
>
> Produces:
>
> Welcome to
> DrRacket, version
> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a)
> [3m].
> Language: r6rs; memory limit: 2000 MB.
> . . procedure application:
> expected procedure, given: # (no arguments)
>
> The code
> expands as follows. The hot spots is marked with an arrow.
>
> (module
> anonymous-module r6rs
>   (#%plain-module-begin
>    (#%require
> r6rs/private/prelims)
>    (#%require (lib
> "rnrs/base-6.rkt"))
>    (#%require (for-meta #f (lib
> "rnrs/base-6.rkt")))
>    (#%require (lib
> "rnrs/io/simple-6.rkt"))
>    (#%require (for-meta #f (lib
> "rnrs/io/simple-6.rkt")))
>    (define-values
> (a)
> (#%plain-lambda
> ()
>   (let-values (((b) undefined) ((c)
> undefined))
>     (let-values ;
> <== prohibits reference to value of previously
> defined var
> (((newtemp)
> (#%plain-lambda () (letrec-values () (let-values () '"who
> cares?"
> ((newtemp:19) (#%app b))) ;
> <==
>   (set! b
> newtemp)
>   (set! c
> newtemp:19)
> (let-values:20 () (let-values:21 () c))
>    (#%app write (#%app
> a
>
> Is this a bug or do I misunderstand
> R6RS?
> The
> following works correct:
>
> #!r6rs
>
> (import
>  (rnrs base
> (6))
>  (rnrs io simple (6)))
>
> (define (a)
> (letrec*
>    ((b (lambda () "who cares?"))
>     (c
> (b)))
>    c))
>
> (write (a))
>
> Thanks,
> Jos
>
>
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] internal definitions in r6rs

2010-09-18 Thread Deren Dohoda
And yet again I am an idiot, as you did not refer to the value of a
binding that *follows* it. Instead you are referring to a value that
precedes it, which should be allowed. Thankfully that does restore my
mental model of the starred lets, though, so apart from several
embarrassing emails on this list I am back where I started. As,
unfortunately, are you.

Deren

On Sat, Sep 18, 2010 at 6:50 PM, Deren Dohoda  wrote:
> Actually, after reading more, letrec* also demands (again page 36, top
> of second column):
>
> "It must be possible to evaluate each  without assigning or
> referring to the value of the corresponding  or the
>  of any of the bindings that follow it in ."
>
> letrec* is not like let* at all, really, which kind of crushes my
> mental model a bit.
>
> It seems, then, that your example at the end using letrec* should not
> work, as you have evaluated an  while referring to the value of
> .
>
> Deren
>
> On Sat, Sep 18, 2010 at 3:37 PM, Jos Koot  wrote:
>> Thanks anyway for taking the trouble to answer.
>> Jos
>>
>>> -Original Message-
>>> From: Deren Dohoda [mailto:[email protected]]
>>> Sent: 18 September 2010 21:35
>>> To: Jos Koot
>>> Cc: PLT-Scheme Mailing List
>>> Subject: Re: [racket] internal definitions in r6rs
>>>
>>> I see, please ignore my last response, as you were talking about
>>> letrec* and not letrec.
>>>
>>> Deren
>>>
>>> On Sat, Sep 18, 2010 at 3:33 PM, Deren Dohoda
>>>  wrote:
>>> > Hi Jos,
>>> >
>>> > (meant to reply to all... sorry)
>>> >
>>> > (letrec () exps ...)
>>> > where  is
>>> > ( ) ...
>>> >
>>> > From page 36 on letrec:
>>> > "It must be possible to evaluate each  without assigning or
>>> > referring to the value of the corresponding  or the
>>> >  of any bindings that follow it in ."
>>> >
>>> > In short:
>>> > you can use the *name* but you can't use the *value*.
>>> >
>>> >> This I interpret as allowing an internal definition to
>>> refer to the
>>> >> value of a previously defined variable.
>>> > It does not. That would be the * forms, which is why your
>>> last example works.
>>> >
>>> > Deren
>>> >
>>> > On Sat, Sep 18, 2010 at 6:52 AM, Jos Koot
>>>  wrote:
>>> >> Hi,
>>> >>
>>> >> Section 11.3 of R6RS states: "An expanded  (see chapter 10)
>>> >> containing variable definitions can always be converted into an
>>> >> equivalent letrec* expression." The semantics of letrec* includes
>>> >> "each  is assigned in left-to-right order". This I
>>> >> interpret as allowing an internal definition to refer to
>>> the value of a previously defined variable. However:
>>> >>
>>> >> #!r6rs
>>> >>
>>> >> (import
>>> >>  (rnrs base (6))
>>> >>  (rnrs io simple (6)))
>>> >>
>>> >> (define (a)
>>> >>   (define (b) "who cares?")
>>> >>   (define c (b))
>>> >>   c)
>>> >>
>>> >> (write (a))
>>> >>
>>> >> Produces:
>>> >>
>>> >> Welcome to DrRacket, version
>>> >>
>>> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
>>> >> Language: r6rs; memory limit: 2000 MB.
>>> >> . . procedure application: expected procedure, given: #
>>> >> (no
>>> >> arguments)
>>> >>
>>> >> The code expands as follows. The hot spots is marked with an arrow.
>>> >>
>>> >> (module anonymous-module r6rs
>>> >>   (#%plain-module-begin
>>> >>    (#%require r6rs/private/prelims)
>>> >>    (#%require (lib "rnrs/base-6.rkt"))
>>> >>    (#%require (for-meta #f (lib "rnrs/base-6.rkt")))
>>> >>    (#%require (lib "rnrs/io/simple-6.rkt"))
>>> >>    (#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
>>> >>    (define-values (a)
>>> >>  (#%plain-lambda
>>> >>   ()
>>> >>   (let-values (((b) undefined) ((c) undefined))
>>> >>     (let-values ; <== prohibits reference to value of
>>> >> previously defined var
>>> >>     (((newtemp)
>>> >>   (#%plain-lambda () (letrec-values () (let-values ()
>>> >> '"who
>>> >> cares?"
>>> >>  ((newtemp:19) (#%app b))) ; <==
>>> >>   (set! b newtemp)
>>> >>   (set! c newtemp:19)
>>> >>   (let-values:20 () (let-values:21 () c))
>>> >>    (#%app write (#%app a
>>> >> Is this a bug or do I misunderstand R6RS?
>>> >> The following works correct:
>>> >>
>>> >> #!r6rs
>>> >>
>>> >> (import
>>> >>  (rnrs base (6))
>>> >>  (rnrs io simple (6)))
>>> >>
>>> >> (define (a)
>>> >>   (letrec*
>>> >>    ((b (lambda () "who cares?"))
>>> >>     (c (b)))
>>> >>    c))
>>> >>
>>> >> (write (a))
>>> >>
>>> >> Thanks, Jos
>>> >> _
>>> >>  For list-related administrative tasks:
>>> >>  http://lists.racket-lang.org/listinfo/users
>>> >>
>>> >
>>
>>
>>
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] internal definitions in r6rs

2010-09-18 Thread Deren Dohoda
Actually, after reading more, letrec* also demands (again page 36, top
of second column):

"It must be possible to evaluate each  without assigning or
referring to the value of the corresponding  or the
 of any of the bindings that follow it in ."

letrec* is not like let* at all, really, which kind of crushes my
mental model a bit.

It seems, then, that your example at the end using letrec* should not
work, as you have evaluated an  while referring to the value of
.

Deren

On Sat, Sep 18, 2010 at 3:37 PM, Jos Koot  wrote:
> Thanks anyway for taking the trouble to answer.
> Jos
>
>> -Original Message-
>> From: Deren Dohoda [mailto:[email protected]]
>> Sent: 18 September 2010 21:35
>> To: Jos Koot
>> Cc: PLT-Scheme Mailing List
>> Subject: Re: [racket] internal definitions in r6rs
>>
>> I see, please ignore my last response, as you were talking about
>> letrec* and not letrec.
>>
>> Deren
>>
>> On Sat, Sep 18, 2010 at 3:33 PM, Deren Dohoda
>>  wrote:
>> > Hi Jos,
>> >
>> > (meant to reply to all... sorry)
>> >
>> > (letrec () exps ...)
>> > where  is
>> > ( ) ...
>> >
>> > From page 36 on letrec:
>> > "It must be possible to evaluate each  without assigning or
>> > referring to the value of the corresponding  or the
>> >  of any bindings that follow it in ."
>> >
>> > In short:
>> > you can use the *name* but you can't use the *value*.
>> >
>> >> This I interpret as allowing an internal definition to
>> refer to the
>> >> value of a previously defined variable.
>> > It does not. That would be the * forms, which is why your
>> last example works.
>> >
>> > Deren
>> >
>> > On Sat, Sep 18, 2010 at 6:52 AM, Jos Koot
>>  wrote:
>> >> Hi,
>> >>
>> >> Section 11.3 of R6RS states: "An expanded  (see chapter 10)
>> >> containing variable definitions can always be converted into an
>> >> equivalent letrec* expression." The semantics of letrec* includes
>> >> "each  is assigned in left-to-right order". This I
>> >> interpret as allowing an internal definition to refer to
>> the value of a previously defined variable. However:
>> >>
>> >> #!r6rs
>> >>
>> >> (import
>> >>  (rnrs base (6))
>> >>  (rnrs io simple (6)))
>> >>
>> >> (define (a)
>> >>   (define (b) "who cares?")
>> >>   (define c (b))
>> >>   c)
>> >>
>> >> (write (a))
>> >>
>> >> Produces:
>> >>
>> >> Welcome to DrRacket, version
>> >>
>> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
>> >> Language: r6rs; memory limit: 2000 MB.
>> >> . . procedure application: expected procedure, given: #
>> >> (no
>> >> arguments)
>> >>
>> >> The code expands as follows. The hot spots is marked with an arrow.
>> >>
>> >> (module anonymous-module r6rs
>> >>   (#%plain-module-begin
>> >>    (#%require r6rs/private/prelims)
>> >>    (#%require (lib "rnrs/base-6.rkt"))
>> >>    (#%require (for-meta #f (lib "rnrs/base-6.rkt")))
>> >>    (#%require (lib "rnrs/io/simple-6.rkt"))
>> >>    (#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
>> >>    (define-values (a)
>> >>  (#%plain-lambda
>> >>   ()
>> >>   (let-values (((b) undefined) ((c) undefined))
>> >>     (let-values ; <== prohibits reference to value of
>> >> previously defined var
>> >>     (((newtemp)
>> >>   (#%plain-lambda () (letrec-values () (let-values ()
>> >> '"who
>> >> cares?"
>> >>  ((newtemp:19) (#%app b))) ; <==
>> >>   (set! b newtemp)
>> >>   (set! c newtemp:19)
>> >>   (let-values:20 () (let-values:21 () c))
>> >>    (#%app write (#%app a
>> >> Is this a bug or do I misunderstand R6RS?
>> >> The following works correct:
>> >>
>> >> #!r6rs
>> >>
>> >> (import
>> >>  (rnrs base (6))
>> >>  (rnrs io simple (6)))
>> >>
>> >> (define (a)
>> >>   (letrec*
>> >>    ((b (lambda () "who cares?"))
>> >>     (c (b)))
>> >>    c))
>> >>
>> >> (write (a))
>> >>
>> >> Thanks, Jos
>> >> _
>> >>  For list-related administrative tasks:
>> >>  http://lists.racket-lang.org/listinfo/users
>> >>
>> >
>
>
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] internal definitions in r6rs

2010-09-18 Thread Jos Koot
Thanks anyway for taking the trouble to answer.
Jos 

> -Original Message-
> From: Deren Dohoda [mailto:[email protected]] 
> Sent: 18 September 2010 21:35
> To: Jos Koot
> Cc: PLT-Scheme Mailing List
> Subject: Re: [racket] internal definitions in r6rs
> 
> I see, please ignore my last response, as you were talking about
> letrec* and not letrec.
> 
> Deren
> 
> On Sat, Sep 18, 2010 at 3:33 PM, Deren Dohoda 
>  wrote:
> > Hi Jos,
> >
> > (meant to reply to all... sorry)
> >
> > (letrec () exps ...)
> > where  is
> > ( ) ...
> >
> > From page 36 on letrec:
> > "It must be possible to evaluate each  without assigning or 
> > referring to the value of the corresponding  or the 
> >  of any bindings that follow it in ."
> >
> > In short:
> > you can use the *name* but you can't use the *value*.
> >
> >> This I interpret as allowing an internal definition to 
> refer to the 
> >> value of a previously defined variable.
> > It does not. That would be the * forms, which is why your 
> last example works.
> >
> > Deren
> >
> > On Sat, Sep 18, 2010 at 6:52 AM, Jos Koot 
>  wrote:
> >> Hi,
> >>
> >> Section 11.3 of R6RS states: "An expanded  (see chapter 10) 
> >> containing variable definitions can always be converted into an 
> >> equivalent letrec* expression." The semantics of letrec* includes 
> >> "each  is assigned in left-to-right order". This I 
> >> interpret as allowing an internal definition to refer to 
> the value of a previously defined variable. However:
> >>
> >> #!r6rs
> >>
> >> (import
> >>  (rnrs base (6))
> >>  (rnrs io simple (6)))
> >>
> >> (define (a)
> >>   (define (b) "who cares?")
> >>   (define c (b))
> >>   c)
> >>
> >> (write (a))
> >>
> >> Produces:
> >>
> >> Welcome to DrRacket, version
> >> 
> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
> >> Language: r6rs; memory limit: 2000 MB.
> >> . . procedure application: expected procedure, given: # 
> >> (no
> >> arguments)
> >>
> >> The code expands as follows. The hot spots is marked with an arrow.
> >>
> >> (module anonymous-module r6rs
> >>   (#%plain-module-begin
> >>    (#%require r6rs/private/prelims)
> >>    (#%require (lib "rnrs/base-6.rkt"))
> >>    (#%require (for-meta #f (lib "rnrs/base-6.rkt")))
> >>    (#%require (lib "rnrs/io/simple-6.rkt"))
> >>    (#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
> >>    (define-values (a)
> >>  (#%plain-lambda
> >>   ()
> >>   (let-values (((b) undefined) ((c) undefined))
> >>     (let-values ; <== prohibits reference to value of 
> >> previously defined var
> >>     (((newtemp)
> >>   (#%plain-lambda () (letrec-values () (let-values () 
> >> '"who
> >> cares?"
> >>  ((newtemp:19) (#%app b))) ; <==
> >>   (set! b newtemp)
> >>   (set! c newtemp:19)
> >>   (let-values:20 () (let-values:21 () c))
> >>    (#%app write (#%app a
> >> Is this a bug or do I misunderstand R6RS?
> >> The following works correct:
> >>
> >> #!r6rs
> >>
> >> (import
> >>  (rnrs base (6))
> >>  (rnrs io simple (6)))
> >>
> >> (define (a)
> >>   (letrec*
> >>    ((b (lambda () "who cares?"))
> >>     (c (b)))
> >>    c))
> >>
> >> (write (a))
> >>
> >> Thanks, Jos
> >> _
> >>  For list-related administrative tasks:
> >>  http://lists.racket-lang.org/listinfo/users
> >>
> >


_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] internal definitions in r6rs

2010-09-18 Thread Deren Dohoda
I see, please ignore my last response, as you were talking about
letrec* and not letrec.

Deren

On Sat, Sep 18, 2010 at 3:33 PM, Deren Dohoda  wrote:
> Hi Jos,
>
> (meant to reply to all... sorry)
>
> (letrec () exps ...)
> where  is
> ( ) ...
>
> From page 36 on letrec:
> "It must be possible to evaluate each  without assigning or
> referring to the value of the corresponding  or the
>  of any bindings that follow it in ."
>
> In short:
> you can use the *name* but you can't use the *value*.
>
>> This I interpret as allowing an internal definition
>> to refer to the value of a previously defined variable.
> It does not. That would be the * forms, which is why your last example works.
>
> Deren
>
> On Sat, Sep 18, 2010 at 6:52 AM, Jos Koot  wrote:
>> Hi,
>>
>> Section 11.3 of R6RS states: "An expanded  (see chapter 10) containing
>> variable definitions can always be converted into an equivalent letrec*
>> expression." The semantics of letrec* includes "each  is assigned
>> in left-to-right order". This I interpret as allowing an internal definition
>> to refer to the value of a previously defined variable. However:
>>
>> #!r6rs
>>
>> (import
>>  (rnrs base (6))
>>  (rnrs io simple (6)))
>>
>> (define (a)
>>   (define (b) "who cares?")
>>   (define c (b))
>>   c)
>>
>> (write (a))
>>
>> Produces:
>>
>> Welcome to DrRacket, version
>> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
>> Language: r6rs; memory limit: 2000 MB.
>> . . procedure application: expected procedure, given: # (no
>> arguments)
>>
>> The code expands as follows. The hot spots is marked with an arrow.
>>
>> (module anonymous-module r6rs
>>   (#%plain-module-begin
>>    (#%require r6rs/private/prelims)
>>    (#%require (lib "rnrs/base-6.rkt"))
>>    (#%require (for-meta #f (lib "rnrs/base-6.rkt")))
>>    (#%require (lib "rnrs/io/simple-6.rkt"))
>>    (#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
>>    (define-values (a)
>>  (#%plain-lambda
>>   ()
>>   (let-values (((b) undefined) ((c) undefined))
>>     (let-values ; <== prohibits reference to value of previously
>> defined var
>>     (((newtemp)
>>   (#%plain-lambda () (letrec-values () (let-values () '"who
>> cares?"
>>  ((newtemp:19) (#%app b))) ; <==
>>   (set! b newtemp)
>>   (set! c newtemp:19)
>>   (let-values:20 () (let-values:21 () c))
>>    (#%app write (#%app a
>> Is this a bug or do I misunderstand R6RS?
>> The following works correct:
>>
>> #!r6rs
>>
>> (import
>>  (rnrs base (6))
>>  (rnrs io simple (6)))
>>
>> (define (a)
>>   (letrec*
>>    ((b (lambda () "who cares?"))
>>     (c (b)))
>>    c))
>>
>> (write (a))
>>
>> Thanks, Jos
>> _
>>  For list-related administrative tasks:
>>  http://lists.racket-lang.org/listinfo/users
>>
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] internal definitions in r6rs

2010-09-18 Thread Deren Dohoda
Hi Jos,

(meant to reply to all... sorry)

(letrec () exps ...)
where  is
( ) ...

>From page 36 on letrec:
"It must be possible to evaluate each  without assigning or
referring to the value of the corresponding  or the
 of any bindings that follow it in ."

In short:
you can use the *name* but you can't use the *value*.

> This I interpret as allowing an internal definition
> to refer to the value of a previously defined variable.
It does not. That would be the * forms, which is why your last example works.

Deren

On Sat, Sep 18, 2010 at 6:52 AM, Jos Koot  wrote:
> Hi,
>
> Section 11.3 of R6RS states: "An expanded  (see chapter 10) containing
> variable definitions can always be converted into an equivalent letrec*
> expression." The semantics of letrec* includes "each  is assigned
> in left-to-right order". This I interpret as allowing an internal definition
> to refer to the value of a previously defined variable. However:
>
> #!r6rs
>
> (import
>  (rnrs base (6))
>  (rnrs io simple (6)))
>
> (define (a)
>   (define (b) "who cares?")
>   (define c (b))
>   c)
>
> (write (a))
>
> Produces:
>
> Welcome to DrRacket, version
> 5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
> Language: r6rs; memory limit: 2000 MB.
> . . procedure application: expected procedure, given: # (no
> arguments)
>
> The code expands as follows. The hot spots is marked with an arrow.
>
> (module anonymous-module r6rs
>   (#%plain-module-begin
>    (#%require r6rs/private/prelims)
>    (#%require (lib "rnrs/base-6.rkt"))
>    (#%require (for-meta #f (lib "rnrs/base-6.rkt")))
>    (#%require (lib "rnrs/io/simple-6.rkt"))
>    (#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
>    (define-values (a)
>  (#%plain-lambda
>   ()
>   (let-values (((b) undefined) ((c) undefined))
>     (let-values ; <== prohibits reference to value of previously
> defined var
>     (((newtemp)
>   (#%plain-lambda () (letrec-values () (let-values () '"who
> cares?"
>  ((newtemp:19) (#%app b))) ; <==
>   (set! b newtemp)
>   (set! c newtemp:19)
>   (let-values:20 () (let-values:21 () c))
>    (#%app write (#%app a
> Is this a bug or do I misunderstand R6RS?
> The following works correct:
>
> #!r6rs
>
> (import
>  (rnrs base (6))
>  (rnrs io simple (6)))
>
> (define (a)
>   (letrec*
>    ((b (lambda () "who cares?"))
>     (c (b)))
>    c))
>
> (write (a))
>
> Thanks, Jos
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


[racket] internal definitions in r6rs

2010-09-18 Thread Jos Koot
Hi,
 
Section 11.3 of R6RS states: "An expanded  (see chapter 10) containing
variable definitions can always be converted into an equivalent letrec*
expression." The semantics of letrec* includes "each  is assigned
in left-to-right order". This I interpret as allowing an internal definition
to refer to the value of a previously defined variable. However:
 
#!r6rs
 
(import
 (rnrs base (6))
 (rnrs io simple (6)))
 
(define (a)
  (define (b) "who cares?")
  (define c (b))
  c)
 
(write (a))
 
Produces:
 
Welcome to DrRacket, version
5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a) [3m].
Language: r6rs; memory limit: 2000 MB.
. . procedure application: expected procedure, given: # (no
arguments)
 
The code expands as follows. The hot spots is marked with an arrow.
 
(module anonymous-module r6rs
  (#%plain-module-begin
   (#%require r6rs/private/prelims)
   (#%require (lib "rnrs/base-6.rkt"))
   (#%require (for-meta #f (lib "rnrs/base-6.rkt")))
   (#%require (lib "rnrs/io/simple-6.rkt"))
   (#%require (for-meta #f (lib "rnrs/io/simple-6.rkt")))
   (define-values (a)
 (#%plain-lambda
  ()
  (let-values (((b) undefined) ((c) undefined))
(let-values ; <== prohibits reference to value of previously
defined var
(((newtemp)
  (#%plain-lambda () (letrec-values () (let-values () '"who
cares?"
 ((newtemp:19) (#%app b))) ; <==
  (set! b newtemp)
  (set! c newtemp:19)
  (let-values:20 () (let-values:21 () c))
   (#%app write (#%app a

Is this a bug or do I misunderstand R6RS?
The following works correct:
 
#!r6rs
 
(import
 (rnrs base (6))
 (rnrs io simple (6)))
 
(define (a)
  (letrec*
   ((b (lambda () "who cares?"))
(c (b)))
   c))
 
(write (a))
 
Thanks, Jos
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users