<br>Yes, in my non-Racket-expert view, the core issue is certainly interactions between toplevel and the module system. It seems unfortunate at best that we have:<br><br>Welcome to DrRacket, version 5.3 [3m].<br>Language: racket; memory limit: 512 MB.<br>
> (define (range lo hi)<br> (print "hi")<br> (if (> lo hi) null (cons lo (range (+ 1 lo) hi))))<br>> (range 3 7)<br>"hi"'(3 4 5 6)<br><br>but:<br><br>Welcome to DrRacket, version 5.3 [3m].<br>
Language: racket; memory limit: 512 MB.<br>> (define range 0)<br>> (define (range lo hi)<br> (print "hi")<br> (if (> lo hi) null (cons lo (range (+ 1 lo) hi))))<br>> (range 3 7)<br>"hi""hi""hi""hi""hi""hi"'(3 4 5 6 7)<br>
> <br><br>I'm sure this is an old topic, but would there be fewer gotchas if the REPL were in its own module, importing whatever was defined by the definitions window?<br><br>(I note that range was not defined in Racket 5.2, but we seem to have the same behavior with map, so this is not a new behavior with respect to the top-level.)<br>
<br>--Dan<br><br><div class="gmail_quote">On Tue, Oct 23, 2012 at 10:02 AM, Jens Axel Søgaard <span dir="ltr"><<a href="mailto:jensaxel@soegaard.net" target="_blank">jensaxel@soegaard.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I forgot to add one rationale for having a context dependent meaning<br>
of define-values. With the current setup, you can write<br>
<br>
(module foo some-lang<br>
(define (range ...) ...))<br>
<br>
without worrying about whether range is defined in some-lang or not.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Jens Axel Søgaard<br>
<br>
<br>
2012/10/23 Jens Axel Søgaard <<a href="mailto:jensaxel@soegaard.net">jensaxel@soegaard.net</a>>:<br>
</font></span><div class="HOEnZb"><div class="h5">> 2012/10/23 Dan Grossman <<a href="mailto:djg@cs.washington.edu">djg@cs.washington.edu</a>>:<br>
>><br>
>> Thanks, David. I would be interested in someone walking through how this<br>
>> behavior arises -- as well as the design issue regarding the "hopeless<br>
>> top-level": Is this the least-bad option available or an unexpected<br>
>> consequence?<br>
>><br>
>> --Dan<br>
><br>
> The expansion in the repl is:<br>
><br>
>> (syntax->datum<br>
> (expand<br>
> '(define (range lo)<br>
> (lambda (hi) (if (> lo hi) null (cons lo ((range (+ 1 lo)) hi)))))))<br>
><br>
> '(define-values<br>
> (range)<br>
> (lambda (lo)<br>
> (lambda (hi)<br>
> (if (#%app > lo hi)<br>
> null<br>
> (#%app cons lo (#%app (#%app range (#%app + '1 lo)) hi))))))<br>
><br>
> The tricky thing here is that the meaning of a define-values form is<br>
> dependent on context:<br>
><br>
> In an internal-definition context (see Internal Definitions), a<br>
> define-values form<br>
> introduces local bindings.<br>
><br>
> At the top level, the top-level binding for each id is created<br>
> after evaluating expr,<br>
> if it does not exist already, and the top-level mapping of each id<br>
> (in the namespace linked with the compiled definition) is set to the binding<br>
> at the same time.<br>
><br>
> An the documentation on an internal-definition context says:<br>
><br>
> A define-values form: The lexical context of all syntax objects<br>
> for the body<br>
> sequence is immediately enriched with bindings for the define-values form.<br>
><br>
> <a href="http://docs.racket-lang.org/reference/define.html?q=define-values&q=repl#(form._((quote._~23~25kernel)._define-values))" target="_blank">http://docs.racket-lang.org/reference/define.html?q=define-values&q=repl#(form._((quote._~23~25kernel)._define-values))</a><br>
><br>
> --<br>
> Jens Axel Søgaard<br>
><br>
><br>
> --<br>
> --<br>
> Jens Axel Søgaard<br>
<br>
<br>
<br>
--<br>
--<br>
Jens Axel Søgaard<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br>