Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2016-01-05 Thread Matthias Felleisen

> On Dec 22, 2015, at 8:46 AM, Matthew Flatt  wrote:
> 
> I think Robby was just confused by your example, because he's used to
> starting with a fresh REPL. :)


When Dan F. and I worked on TLL/3 way back in the 80s together, we 
confused ourselves several times with just HO functions and some aux
macros to set things up (for ch 8 I think) so much that we decided we’d
never, ever use the REPL for more than a few interactions and then re-start. 
(If you watched Dan F’s SL talk this year, he still does this.) 

Of course, at the time the macro system was much simpler and less expressive, 
the IDE was plain Emacs, but the top-level, it was already hopeless back then. 

— Matthias

p.s. BTW, this is where DrRacket’s “transparent” top-level comes from: it’s 
a mechanical version of Dan F presenting code from 1988 or 1989 or something
like that ;-) 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-22 Thread Leif Andersen
Okay, thank you for the explanation.

I totally see what you mean now by the top level being hopeless. (Or
at least I think I do.) It seems there is no way to get a meaning that
does everything  we would want it to...

As a side not Matthew, I notice that you seem to be sending out two
identical emails every time you send out an email. If memory serves
you use Mr Ed, right? I wonder if that might be a bug.

~Leif Andersen


On Tue, Dec 22, 2015 at 6:54 AM, Robby Findler
 wrote:
> Oh right. Sorry for the confusion!
>
> Robby
>
>
> On Tuesday, December 22, 2015, Matthew Flatt  wrote:
>>
>> I think Robby was confused by your example (which is understandable).
>>
>> The `expand` function does not splice any differently than `compile`,
>> so `compile` behaves the same as `expand` in your example:
>>
>>  >  (eval (compile #'(begin
>>   (define-syntax (foo stx)
>> (displayln "hello")
>> #'5)
>>   foo)))
>>  foo: undefined;
>>   cannot reference undefined identifier
>>context...:
>> /Users/mflatt/plt/racket/collects/racket/private/misc.rkt:87:7
>>  > (compile #'(begin
>>   (define-syntax (foo stx)
>> (displayln "goodbye")
>> #'5)
>>   foo))
>>  hello
>>  #~
>>
>>
>> I think Robby was just confused by your example, because he's used to
>> starting with a fresh REPL. :)
>>
>> At Mon, 21 Dec 2015 22:16:44 -0700, Leif Andersen wrote:
>> > Wait, now I'm even more confused. If expand does the splicing and
>> > compile time evals song and dance, why do we need a separate function
>> > for:
>> >
>> > expand-syntax-top-level-with-compile-time-evals
>> >
>> > ?
>> >
>> > ~Leif Andersen
>> >
>> >
>> > On Mon, Dec 21, 2015 at 9:48 PM, Robby Findler
>> >  wrote:
>> > > I believe that's because expand does the splicing dance, but compile
>> > > doesn't (which is why you need the funny-named function ... "need" is
>> > > perhaps a poor choice of words here :).
>> > >
>> > > Robby
>> > >
>> > >
>> > > On Mon, Dec 21, 2015 at 10:30 PM, Leif Andersen
>> > > 
>> > wrote:
>> > >> Ah, that's a good question. One that I don't really know the answer
>> > >> too, because when I do:
>> > >>
>> > >>> (compile #'(begin
>> > >>(define-syntax (foo stx)
>> > >>  (displayln "hello")
>> > >>  #'5)
>> > >>foo))
>> > >>
>> > >> I get back the compiled object. Also foo is not displayed. And when I
>> > >> do:
>> > >>
>> > >>  > (eval (compile #'(begin
>> > >>(define-syntax (foo stx)
>> > >>  (displayln "hello")
>> > >>  #'5)
>> > >>foo)))
>> > >>
>> > >> I get the error:
>> > >>
>> > >> foo: undefined;
>> > >>  cannot reference an identifier before its definition
>> > >>
>> > >> But, when I do:
>> > >>
>> > >>> (expand #'(begin
>> > >>(define-syntax (foo stx)
>> > >>  (displayln "hello")
>> > >>  #'5)
>> > >>foo))
>> > >>
>> > >> It displays 'hello' to the console. And expands to what I would
>> > >> expect it
>> > too.
>> > >>
>> > >> ~Leif Andersen
>> > >>
>> > >>
>> > >> On Mon, Dec 21, 2015 at 9:15 PM, Alex Knauth 
>> > >> wrote:
>> > >>>
>> >  On Dec 21, 2015, at 10:53 PM, Leif Andersen 
>> >  wrote:
>> > >>>
>> >  But `compile` is not supposed to evaluate any code, it just
>> >  compiles
>> >  it. Which is why it fails to compile that code. But if you
>> >  interleave
>> >  it with evals, it will run the require code, which gives the phase
>> >  level 2 code some meaning.
>> > >>>
>> > >>> I understand that `compile` isn't supposed to evaluate any _runtime_
>> > >>> code,
>> > but I thought it had to evaluate the compile-time code for it to compile
>> > the
>> > program?
>> > >>>
>> > >>> Am I misunderstanding what `compile` is supposed to do? Or what
>> > compile-time code is, or?
>> > >>>
>> >  Does that make any sense, or was it too rambly.
>> > 
>> >  ~Leif Andersen
>> > 
>> > 
>> >  On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth 
>> >  wrote:
>> > > I get that `compile` doesn't evaluate the require form, but why
>> > > doesn't
>> > it evaluate what's needed for compile time? I thought that was the
>> > reason for
>> > needing require as a macro instead of a function. Or am I getting the
>> > purpose
>> > of compile wrong?
>> > >
>> > > Alex Knauth
>> > >
>> > >> On Dec 21, 2015, at 7:47 PM, Matthew Flatt 
>> > >> wrote:
>> > >>
>> > >> In the REPL, `begin` splices at the granularity of expansion and
>> > >> evaluation. That is, the first of the two forms grouped by
>> > >> `begin` is
>> > >> compiled and evaluated, and only afterward the second one is
>> > >> compiled
>> > >> and evaluated.
>> > >>
>> > >> The `compile` function can't do that, because it's only supposed
>> > >

Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-22 Thread Robby Findler
Oh right. Sorry for the confusion!

Robby

On Tuesday, December 22, 2015, Matthew Flatt  wrote:

> I think Robby was confused by your example (which is understandable).
>
> The `expand` function does not splice any differently than `compile`,
> so `compile` behaves the same as `expand` in your example:
>
>  >  (eval (compile #'(begin
>   (define-syntax (foo stx)
> (displayln "hello")
> #'5)
>   foo)))
>  foo: undefined;
>   cannot reference undefined identifier
>context...:
> /Users/mflatt/plt/racket/collects/racket/private/misc.rkt:87:7
>  > (compile #'(begin
>   (define-syntax (foo stx)
> (displayln "goodbye")
> #'5)
>   foo))
>  hello
>  #~
>
>
> I think Robby was just confused by your example, because he's used to
> starting with a fresh REPL. :)
>
> At Mon, 21 Dec 2015 22:16:44 -0700, Leif Andersen wrote:
> > Wait, now I'm even more confused. If expand does the splicing and
> > compile time evals song and dance, why do we need a separate function
> > for:
> >
> > expand-syntax-top-level-with-compile-time-evals
> >
> > ?
> >
> > ~Leif Andersen
> >
> >
> > On Mon, Dec 21, 2015 at 9:48 PM, Robby Findler
> > > wrote:
> > > I believe that's because expand does the splicing dance, but compile
> > > doesn't (which is why you need the funny-named function ... "need" is
> > > perhaps a poor choice of words here :).
> > >
> > > Robby
> > >
> > >
> > > On Mon, Dec 21, 2015 at 10:30 PM, Leif Andersen  >
> > wrote:
> > >> Ah, that's a good question. One that I don't really know the answer
> > >> too, because when I do:
> > >>
> > >>> (compile #'(begin
> > >>(define-syntax (foo stx)
> > >>  (displayln "hello")
> > >>  #'5)
> > >>foo))
> > >>
> > >> I get back the compiled object. Also foo is not displayed. And when I
> do:
> > >>
> > >>  > (eval (compile #'(begin
> > >>(define-syntax (foo stx)
> > >>  (displayln "hello")
> > >>  #'5)
> > >>foo)))
> > >>
> > >> I get the error:
> > >>
> > >> foo: undefined;
> > >>  cannot reference an identifier before its definition
> > >>
> > >> But, when I do:
> > >>
> > >>> (expand #'(begin
> > >>(define-syntax (foo stx)
> > >>  (displayln "hello")
> > >>  #'5)
> > >>foo))
> > >>
> > >> It displays 'hello' to the console. And expands to what I would
> expect it
> > too.
> > >>
> > >> ~Leif Andersen
> > >>
> > >>
> > >> On Mon, Dec 21, 2015 at 9:15 PM, Alex Knauth  > wrote:
> > >>>
> >  On Dec 21, 2015, at 10:53 PM, Leif Andersen  > wrote:
> > >>>
> >  But `compile` is not supposed to evaluate any code, it just compiles
> >  it. Which is why it fails to compile that code. But if you
> interleave
> >  it with evals, it will run the require code, which gives the phase
> >  level 2 code some meaning.
> > >>>
> > >>> I understand that `compile` isn't supposed to evaluate any _runtime_
> code,
> > but I thought it had to evaluate the compile-time code for it to compile
> the
> > program?
> > >>>
> > >>> Am I misunderstanding what `compile` is supposed to do? Or what
> > compile-time code is, or?
> > >>>
> >  Does that make any sense, or was it too rambly.
> > 
> >  ~Leif Andersen
> > 
> > 
> >  On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  > wrote:
> > > I get that `compile` doesn't evaluate the require form, but why
> doesn't
> > it evaluate what's needed for compile time? I thought that was the
> reason for
> > needing require as a macro instead of a function. Or am I getting the
> purpose
> > of compile wrong?
> > >
> > > Alex Knauth
> > >
> > >> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  > wrote:
> > >>
> > >> In the REPL, `begin` splices at the granularity of expansion and
> > >> evaluation. That is, the first of the two forms grouped by
> `begin` is
> > >> compiled and evaluated, and only afterward the second one is
> compiled
> > >> and evaluated.
> > >>
> > >> The `compile` function can't do that, because it's only supposed
> to
> > >> compile -- not evaluate.
> > >>
> > >> The `syntax/toplevel` library provides
> > >>
> > >> expand-syntax-top-level-with-compile-time-evals
> > >>
> > >> as an intermediate point between those: it pulls apart `begin` and
> > >> `expands` (which is the interesting part of `compile`) the forms
> in
> > >> sequence, but it evaluates only compile-time parts of the given
> forms.
> > >> That works for many cases, including your example.
> > >>
> > >> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
> > >>> So, I was under the impression that the REPL was the toplevel
> (unless
> > >>> you entered a module context or something like that). But I just
> had

Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-22 Thread Matthew Flatt
I think Robby was confused by your example (which is understandable).

The `expand` function does not splice any differently than `compile`,
so `compile` behaves the same as `expand` in your example:

 >  (eval (compile #'(begin
  (define-syntax (foo stx)
(displayln "hello")
#'5)
  foo)))
 foo: undefined;
  cannot reference undefined identifier
   context...:
/Users/mflatt/plt/racket/collects/racket/private/misc.rkt:87:7
 > (compile #'(begin
  (define-syntax (foo stx)
(displayln "goodbye")
#'5)
  foo))
 hello
 #~


I think Robby was just confused by your example, because he's used to
starting with a fresh REPL. :)

At Mon, 21 Dec 2015 22:16:44 -0700, Leif Andersen wrote:
> Wait, now I'm even more confused. If expand does the splicing and
> compile time evals song and dance, why do we need a separate function
> for:
> 
> expand-syntax-top-level-with-compile-time-evals
> 
> ?
> 
> ~Leif Andersen
> 
> 
> On Mon, Dec 21, 2015 at 9:48 PM, Robby Findler
>  wrote:
> > I believe that's because expand does the splicing dance, but compile
> > doesn't (which is why you need the funny-named function ... "need" is
> > perhaps a poor choice of words here :).
> >
> > Robby
> >
> >
> > On Mon, Dec 21, 2015 at 10:30 PM, Leif Andersen  
> wrote:
> >> Ah, that's a good question. One that I don't really know the answer
> >> too, because when I do:
> >>
> >>> (compile #'(begin
> >>(define-syntax (foo stx)
> >>  (displayln "hello")
> >>  #'5)
> >>foo))
> >>
> >> I get back the compiled object. Also foo is not displayed. And when I do:
> >>
> >>  > (eval (compile #'(begin
> >>(define-syntax (foo stx)
> >>  (displayln "hello")
> >>  #'5)
> >>foo)))
> >>
> >> I get the error:
> >>
> >> foo: undefined;
> >>  cannot reference an identifier before its definition
> >>
> >> But, when I do:
> >>
> >>> (expand #'(begin
> >>(define-syntax (foo stx)
> >>  (displayln "hello")
> >>  #'5)
> >>foo))
> >>
> >> It displays 'hello' to the console. And expands to what I would expect it 
> too.
> >>
> >> ~Leif Andersen
> >>
> >>
> >> On Mon, Dec 21, 2015 at 9:15 PM, Alex Knauth  wrote:
> >>>
>  On Dec 21, 2015, at 10:53 PM, Leif Andersen  
>  wrote:
> >>>
>  But `compile` is not supposed to evaluate any code, it just compiles
>  it. Which is why it fails to compile that code. But if you interleave
>  it with evals, it will run the require code, which gives the phase
>  level 2 code some meaning.
> >>>
> >>> I understand that `compile` isn't supposed to evaluate any _runtime_ 
> >>> code, 
> but I thought it had to evaluate the compile-time code for it to compile the 
> program?
> >>>
> >>> Am I misunderstanding what `compile` is supposed to do? Or what 
> compile-time code is, or?
> >>>
>  Does that make any sense, or was it too rambly.
> 
>  ~Leif Andersen
> 
> 
>  On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  
>  wrote:
> > I get that `compile` doesn't evaluate the require form, but why doesn't 
> it evaluate what's needed for compile time? I thought that was the reason for 
> needing require as a macro instead of a function. Or am I getting the purpose 
> of compile wrong?
> >
> > Alex Knauth
> >
> >> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
> >>
> >> In the REPL, `begin` splices at the granularity of expansion and
> >> evaluation. That is, the first of the two forms grouped by `begin` is
> >> compiled and evaluated, and only afterward the second one is compiled
> >> and evaluated.
> >>
> >> The `compile` function can't do that, because it's only supposed to
> >> compile -- not evaluate.
> >>
> >> The `syntax/toplevel` library provides
> >>
> >> expand-syntax-top-level-with-compile-time-evals
> >>
> >> as an intermediate point between those: it pulls apart `begin` and
> >> `expands` (which is the interesting part of `compile`) the forms in
> >> sequence, but it evaluates only compile-time parts of the given forms.
> >> That works for many cases, including your example.
> >>
> >> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
> >>> So, I was under the impression that the REPL was the toplevel (unless
> >>> you entered a module context or something like that). But I just had
> >>> something challenge that assumption and so now I'm a bit confused.
> >>>
> >>> I have the following top level program:
> >>>
> >>> (begin
> >>> (require (for-meta 1 racket)
> >>>  (for-meta 2 racket))
> >>> (begin-for-syntax
> >>>   (begin-for-syntax
> >>> (define x 5
> >>>
> >>> When I run thi

Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-22 Thread Matthew Flatt
Expanding a form triggers compile-time evaluation in the sense of
running macros. Currently, though, compilation treats changing the set
of bindings at the top level as a kind of run-time effect (to be
avoided at compile time).

For example, compiling `(define x 5)` does not change the current
binding of `x` at the top level:

 > (require (only-in racket [+ x]))
 > (define code (compile #'(define x 5)))
 > (x 1 2)
 3

Evaluating the compiled form of `(define x 5)` does change the binding f `x`:

 > (eval code)
 > x
 5

It seems clear that top-level binding needs to be a run-time effect in
that latter sense, but maybe it could also happen as a compile-time
effect. That would be a significant change, though; some things would
break. As it happens, the new expander at first leaked a binding effect
when compiling `define` --- until Leif reported it as a bug and I fixed
it.

Neither the current interaction of `compile` and binding or the
alternative seems obviously right to me, though. As you know, I've
given up on finding completely satisfactory rules for the top level.

At Mon, 21 Dec 2015 23:15:58 -0500, Alex Knauth wrote:
> 
> > On Dec 21, 2015, at 10:53 PM, Leif Andersen  wrote:
> 
> > But `compile` is not supposed to evaluate any code, it just compiles
> > it. Which is why it fails to compile that code. But if you interleave
> > it with evals, it will run the require code, which gives the phase
> > level 2 code some meaning.
> 
> I understand that `compile` isn't supposed to evaluate any _runtime_ code, 
> but 
> I thought it had to evaluate the compile-time code for it to compile the 
> program?
> 
> Am I misunderstanding what `compile` is supposed to do? Or what compile-time 
> code is, or?
> 
> > Does that make any sense, or was it too rambly.
> > 
> > ~Leif Andersen
> > 
> > 
> > On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  wrote:
> >> I get that `compile` doesn't evaluate the require form, but why doesn't it 
> evaluate what's needed for compile time? I thought that was the reason for 
> needing require as a macro instead of a function. Or am I getting the purpose 
> of compile wrong?
> >> 
> >> Alex Knauth
> >> 
> >>> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
> >>> 
> >>> In the REPL, `begin` splices at the granularity of expansion and
> >>> evaluation. That is, the first of the two forms grouped by `begin` is
> >>> compiled and evaluated, and only afterward the second one is compiled
> >>> and evaluated.
> >>> 
> >>> The `compile` function can't do that, because it's only supposed to
> >>> compile -- not evaluate.
> >>> 
> >>> The `syntax/toplevel` library provides
> >>> 
> >>> expand-syntax-top-level-with-compile-time-evals
> >>> 
> >>> as an intermediate point between those: it pulls apart `begin` and
> >>> `expands` (which is the interesting part of `compile`) the forms in
> >>> sequence, but it evaluates only compile-time parts of the given forms.
> >>> That works for many cases, including your example.
> >>> 
> >>> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
>  So, I was under the impression that the REPL was the toplevel (unless
>  you entered a module context or something like that). But I just had
>  something challenge that assumption and so now I'm a bit confused.
>  
>  I have the following top level program:
>  
>  (begin
>  (require (for-meta 1 racket)
>   (for-meta 2 racket))
>  (begin-for-syntax
>    (begin-for-syntax
>  (define x 5
>  
>  When I run this top level program in the REPL, it works just fine. And
>  I can even reference x in later evaluations. (Provided I'm at the
>  meta-level of 2).
>  
>  However, when I pass this top level program into compile like so:
>  http://pasterack.org/pastes/38556
>  
>  (compile #'(begin
> (require (for-meta 1 racket)
>  (for-meta 2 racket))
> (begin-for-syntax
>   (begin-for-syntax
> (define x 5)
>  
>  
>  I get the following error:
>  
>  define: unbound identifier at phase 2;
>  also, no #%app syntax transformer is bound in: define
>  
>  Can someone give me the reason (or at least some intuition) as to why
>  this works in the repl, but not at the top level?
>  
>  Thank you.
>  
>  ~Leif Andersen
>  
>  --
>  You received this message because you are subscribed to the Google Groups
>  "Racket Users" group.
>  To unsubscribe from this group and stop receiving emails from it, send an
>  email to racket-users+unsubscr...@googlegroups.com.
>  For more options, visit https://groups.google.com/d/optout.
> >>> 
> >>> --
> >>> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> >>> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googleg

Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-22 Thread Matthew Flatt
At Mon, 21 Dec 2015 21:30:45 -0700, Leif Andersen wrote:
> Ah, that's a good question. One that I don't really know the answer
> too, because when I do:
> 
> > (compile #'(begin
>(define-syntax (foo stx)
>  (displayln "hello")
>  #'5)
>foo))
> 
> I get back the compiled object. 

The compiled object ends with a reference to a top-level `foo`
variable, not an expansion of the `foo` macro.

> Also foo is not displayed.

That's because the `foo` macro was only compiled, not bound, and so the
ending `foo` didn't reference it.

>  And when I do:
> 
>  > (eval (compile #'(begin
>(define-syntax (foo stx)
>  (displayln "hello")
>  #'5)
>foo)))
> 
> I get the error:
> 
> foo: undefined;
>  cannot reference an identifier before its definition

That demonstrates the reference to `foo`, which is never defined as a
variable.

Confusingly, however, `foo` at this point is bound to a macro. To make
sense of that, you have to remember that there are two levels to
identifier resolution. The first is a binding layer that points `foo`
to either a module import, a top-level macro, or a top-level variable.
In the case of a variable, a second layer maps the variable name to its
value. Compilation commits to a choice in the first layer; it commits
to the the `foo` as a variable reference before that first layer is
changed to make `foo` a macro.

> But, when I do:
> 
> > (expand #'(begin
>(define-syntax (foo stx)
>  (displayln "hello")
>  #'5)
>foo))
> 
> It displays 'hello' to the console. And expands to what I would expect it too.

That example doesn't display anything if you try it in a fresh REPL.
But if you continue in the same REPL as the previous `eval`, then it's
the other `foo` that gets used as a macro here, not this one.


> On Mon, Dec 21, 2015 at 9:15 PM, Alex Knauth  wrote:
> >
> >> On Dec 21, 2015, at 10:53 PM, Leif Andersen  wrote:
> >
> >> But `compile` is not supposed to evaluate any code, it just compiles
> >> it. Which is why it fails to compile that code. But if you interleave
> >> it with evals, it will run the require code, which gives the phase
> >> level 2 code some meaning.
> >
> > I understand that `compile` isn't supposed to evaluate any _runtime_ code, 
> but I thought it had to evaluate the compile-time code for it to compile the 
> program?
> >
> > Am I misunderstanding what `compile` is supposed to do? Or what 
> > compile-time 
> code is, or?
> >
> >> Does that make any sense, or was it too rambly.
> >>
> >> ~Leif Andersen
> >>
> >>
> >> On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  wrote:
> >>> I get that `compile` doesn't evaluate the require form, but why doesn't 
> >>> it 
> evaluate what's needed for compile time? I thought that was the reason for 
> needing require as a macro instead of a function. Or am I getting the purpose 
> of compile wrong?
> >>>
> >>> Alex Knauth
> >>>
>  On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
> 
>  In the REPL, `begin` splices at the granularity of expansion and
>  evaluation. That is, the first of the two forms grouped by `begin` is
>  compiled and evaluated, and only afterward the second one is compiled
>  and evaluated.
> 
>  The `compile` function can't do that, because it's only supposed to
>  compile -- not evaluate.
> 
>  The `syntax/toplevel` library provides
> 
>  expand-syntax-top-level-with-compile-time-evals
> 
>  as an intermediate point between those: it pulls apart `begin` and
>  `expands` (which is the interesting part of `compile`) the forms in
>  sequence, but it evaluates only compile-time parts of the given forms.
>  That works for many cases, including your example.
> 
>  At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
> > So, I was under the impression that the REPL was the toplevel (unless
> > you entered a module context or something like that). But I just had
> > something challenge that assumption and so now I'm a bit confused.
> >
> > I have the following top level program:
> >
> > (begin
> > (require (for-meta 1 racket)
> >  (for-meta 2 racket))
> > (begin-for-syntax
> >   (begin-for-syntax
> > (define x 5
> >
> > When I run this top level program in the REPL, it works just fine. And
> > I can even reference x in later evaluations. (Provided I'm at the
> > meta-level of 2).
> >
> > However, when I pass this top level program into compile like so:
> > http://pasterack.org/pastes/38556
> >
> > (compile #'(begin
> >(require (for-meta 1 racket)
> > (for-meta 2 racket))
> >(begin-for-syntax
> >  (begin-for-syntax
> >(define x 5)
> >
> >
> > I get the

Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Leif Andersen
Wait, now I'm even more confused. If expand does the splicing and
compile time evals song and dance, why do we need a separate function
for:

expand-syntax-top-level-with-compile-time-evals

?

~Leif Andersen


On Mon, Dec 21, 2015 at 9:48 PM, Robby Findler
 wrote:
> I believe that's because expand does the splicing dance, but compile
> doesn't (which is why you need the funny-named function ... "need" is
> perhaps a poor choice of words here :).
>
> Robby
>
>
> On Mon, Dec 21, 2015 at 10:30 PM, Leif Andersen  wrote:
>> Ah, that's a good question. One that I don't really know the answer
>> too, because when I do:
>>
>>> (compile #'(begin
>>(define-syntax (foo stx)
>>  (displayln "hello")
>>  #'5)
>>foo))
>>
>> I get back the compiled object. Also foo is not displayed. And when I do:
>>
>>  > (eval (compile #'(begin
>>(define-syntax (foo stx)
>>  (displayln "hello")
>>  #'5)
>>foo)))
>>
>> I get the error:
>>
>> foo: undefined;
>>  cannot reference an identifier before its definition
>>
>> But, when I do:
>>
>>> (expand #'(begin
>>(define-syntax (foo stx)
>>  (displayln "hello")
>>  #'5)
>>foo))
>>
>> It displays 'hello' to the console. And expands to what I would expect it 
>> too.
>>
>> ~Leif Andersen
>>
>>
>> On Mon, Dec 21, 2015 at 9:15 PM, Alex Knauth  wrote:
>>>
 On Dec 21, 2015, at 10:53 PM, Leif Andersen  wrote:
>>>
 But `compile` is not supposed to evaluate any code, it just compiles
 it. Which is why it fails to compile that code. But if you interleave
 it with evals, it will run the require code, which gives the phase
 level 2 code some meaning.
>>>
>>> I understand that `compile` isn't supposed to evaluate any _runtime_ code, 
>>> but I thought it had to evaluate the compile-time code for it to compile 
>>> the program?
>>>
>>> Am I misunderstanding what `compile` is supposed to do? Or what 
>>> compile-time code is, or?
>>>
 Does that make any sense, or was it too rambly.

 ~Leif Andersen


 On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  wrote:
> I get that `compile` doesn't evaluate the require form, but why doesn't 
> it evaluate what's needed for compile time? I thought that was the reason 
> for needing require as a macro instead of a function. Or am I getting the 
> purpose of compile wrong?
>
> Alex Knauth
>
>> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
>>
>> In the REPL, `begin` splices at the granularity of expansion and
>> evaluation. That is, the first of the two forms grouped by `begin` is
>> compiled and evaluated, and only afterward the second one is compiled
>> and evaluated.
>>
>> The `compile` function can't do that, because it's only supposed to
>> compile -- not evaluate.
>>
>> The `syntax/toplevel` library provides
>>
>> expand-syntax-top-level-with-compile-time-evals
>>
>> as an intermediate point between those: it pulls apart `begin` and
>> `expands` (which is the interesting part of `compile`) the forms in
>> sequence, but it evaluates only compile-time parts of the given forms.
>> That works for many cases, including your example.
>>
>> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
>>> So, I was under the impression that the REPL was the toplevel (unless
>>> you entered a module context or something like that). But I just had
>>> something challenge that assumption and so now I'm a bit confused.
>>>
>>> I have the following top level program:
>>>
>>> (begin
>>> (require (for-meta 1 racket)
>>>  (for-meta 2 racket))
>>> (begin-for-syntax
>>>   (begin-for-syntax
>>> (define x 5
>>>
>>> When I run this top level program in the REPL, it works just fine. And
>>> I can even reference x in later evaluations. (Provided I'm at the
>>> meta-level of 2).
>>>
>>> However, when I pass this top level program into compile like so:
>>> http://pasterack.org/pastes/38556
>>>
>>> (compile #'(begin
>>>(require (for-meta 1 racket)
>>> (for-meta 2 racket))
>>>(begin-for-syntax
>>>  (begin-for-syntax
>>>(define x 5)
>>>
>>>
>>> I get the following error:
>>>
>>> define: unbound identifier at phase 2;
>>> also, no #%app syntax transformer is bound in: define
>>>
>>> Can someone give me the reason (or at least some intuition) as to why
>>> this works in the repl, but not at the top level?
>>>
>>> Thank you.
>>>
>>> ~Leif Andersen
>>>
>>> --
>>> You received this message because you are subscribed to the Google 
>>> Groups
>>> "Racket Users" group.
>>> To unsubscribe from

Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Robby Findler
I believe that's because expand does the splicing dance, but compile
doesn't (which is why you need the funny-named function ... "need" is
perhaps a poor choice of words here :).

Robby


On Mon, Dec 21, 2015 at 10:30 PM, Leif Andersen  wrote:
> Ah, that's a good question. One that I don't really know the answer
> too, because when I do:
>
>> (compile #'(begin
>(define-syntax (foo stx)
>  (displayln "hello")
>  #'5)
>foo))
>
> I get back the compiled object. Also foo is not displayed. And when I do:
>
>  > (eval (compile #'(begin
>(define-syntax (foo stx)
>  (displayln "hello")
>  #'5)
>foo)))
>
> I get the error:
>
> foo: undefined;
>  cannot reference an identifier before its definition
>
> But, when I do:
>
>> (expand #'(begin
>(define-syntax (foo stx)
>  (displayln "hello")
>  #'5)
>foo))
>
> It displays 'hello' to the console. And expands to what I would expect it too.
>
> ~Leif Andersen
>
>
> On Mon, Dec 21, 2015 at 9:15 PM, Alex Knauth  wrote:
>>
>>> On Dec 21, 2015, at 10:53 PM, Leif Andersen  wrote:
>>
>>> But `compile` is not supposed to evaluate any code, it just compiles
>>> it. Which is why it fails to compile that code. But if you interleave
>>> it with evals, it will run the require code, which gives the phase
>>> level 2 code some meaning.
>>
>> I understand that `compile` isn't supposed to evaluate any _runtime_ code, 
>> but I thought it had to evaluate the compile-time code for it to compile the 
>> program?
>>
>> Am I misunderstanding what `compile` is supposed to do? Or what compile-time 
>> code is, or?
>>
>>> Does that make any sense, or was it too rambly.
>>>
>>> ~Leif Andersen
>>>
>>>
>>> On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  wrote:
 I get that `compile` doesn't evaluate the require form, but why doesn't it 
 evaluate what's needed for compile time? I thought that was the reason for 
 needing require as a macro instead of a function. Or am I getting the 
 purpose of compile wrong?

 Alex Knauth

> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
>
> In the REPL, `begin` splices at the granularity of expansion and
> evaluation. That is, the first of the two forms grouped by `begin` is
> compiled and evaluated, and only afterward the second one is compiled
> and evaluated.
>
> The `compile` function can't do that, because it's only supposed to
> compile -- not evaluate.
>
> The `syntax/toplevel` library provides
>
> expand-syntax-top-level-with-compile-time-evals
>
> as an intermediate point between those: it pulls apart `begin` and
> `expands` (which is the interesting part of `compile`) the forms in
> sequence, but it evaluates only compile-time parts of the given forms.
> That works for many cases, including your example.
>
> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
>> So, I was under the impression that the REPL was the toplevel (unless
>> you entered a module context or something like that). But I just had
>> something challenge that assumption and so now I'm a bit confused.
>>
>> I have the following top level program:
>>
>> (begin
>> (require (for-meta 1 racket)
>>  (for-meta 2 racket))
>> (begin-for-syntax
>>   (begin-for-syntax
>> (define x 5
>>
>> When I run this top level program in the REPL, it works just fine. And
>> I can even reference x in later evaluations. (Provided I'm at the
>> meta-level of 2).
>>
>> However, when I pass this top level program into compile like so:
>> http://pasterack.org/pastes/38556
>>
>> (compile #'(begin
>>(require (for-meta 1 racket)
>> (for-meta 2 racket))
>>(begin-for-syntax
>>  (begin-for-syntax
>>(define x 5)
>>
>>
>> I get the following error:
>>
>> define: unbound identifier at phase 2;
>> also, no #%app syntax transformer is bound in: define
>>
>> Can someone give me the reason (or at least some intuition) as to why
>> this works in the repl, but not at the top level?
>>
>> Thank you.
>>
>> ~Leif Andersen
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubs

Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Leif Andersen
Ah, that's a good question. One that I don't really know the answer
too, because when I do:

> (compile #'(begin
   (define-syntax (foo stx)
 (displayln "hello")
 #'5)
   foo))

I get back the compiled object. Also foo is not displayed. And when I do:

 > (eval (compile #'(begin
   (define-syntax (foo stx)
 (displayln "hello")
 #'5)
   foo)))

I get the error:

foo: undefined;
 cannot reference an identifier before its definition

But, when I do:

> (expand #'(begin
   (define-syntax (foo stx)
 (displayln "hello")
 #'5)
   foo))

It displays 'hello' to the console. And expands to what I would expect it too.

~Leif Andersen


On Mon, Dec 21, 2015 at 9:15 PM, Alex Knauth  wrote:
>
>> On Dec 21, 2015, at 10:53 PM, Leif Andersen  wrote:
>
>> But `compile` is not supposed to evaluate any code, it just compiles
>> it. Which is why it fails to compile that code. But if you interleave
>> it with evals, it will run the require code, which gives the phase
>> level 2 code some meaning.
>
> I understand that `compile` isn't supposed to evaluate any _runtime_ code, 
> but I thought it had to evaluate the compile-time code for it to compile the 
> program?
>
> Am I misunderstanding what `compile` is supposed to do? Or what compile-time 
> code is, or?
>
>> Does that make any sense, or was it too rambly.
>>
>> ~Leif Andersen
>>
>>
>> On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  wrote:
>>> I get that `compile` doesn't evaluate the require form, but why doesn't it 
>>> evaluate what's needed for compile time? I thought that was the reason for 
>>> needing require as a macro instead of a function. Or am I getting the 
>>> purpose of compile wrong?
>>>
>>> Alex Knauth
>>>
 On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:

 In the REPL, `begin` splices at the granularity of expansion and
 evaluation. That is, the first of the two forms grouped by `begin` is
 compiled and evaluated, and only afterward the second one is compiled
 and evaluated.

 The `compile` function can't do that, because it's only supposed to
 compile -- not evaluate.

 The `syntax/toplevel` library provides

 expand-syntax-top-level-with-compile-time-evals

 as an intermediate point between those: it pulls apart `begin` and
 `expands` (which is the interesting part of `compile`) the forms in
 sequence, but it evaluates only compile-time parts of the given forms.
 That works for many cases, including your example.

 At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
> So, I was under the impression that the REPL was the toplevel (unless
> you entered a module context or something like that). But I just had
> something challenge that assumption and so now I'm a bit confused.
>
> I have the following top level program:
>
> (begin
> (require (for-meta 1 racket)
>  (for-meta 2 racket))
> (begin-for-syntax
>   (begin-for-syntax
> (define x 5
>
> When I run this top level program in the REPL, it works just fine. And
> I can even reference x in later evaluations. (Provided I'm at the
> meta-level of 2).
>
> However, when I pass this top level program into compile like so:
> http://pasterack.org/pastes/38556
>
> (compile #'(begin
>(require (for-meta 1 racket)
> (for-meta 2 racket))
>(begin-for-syntax
>  (begin-for-syntax
>(define x 5)
>
>
> I get the following error:
>
> define: unbound identifier at phase 2;
> also, no #%app syntax transformer is bound in: define
>
> Can someone give me the reason (or at least some intuition) as to why
> this works in the repl, but not at the top level?
>
> Thank you.
>
> ~Leif Andersen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

 --
 You received this message because you are subscribed to the Google Groups 
 "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to racket-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
>>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Alex Knauth

> On Dec 21, 2015, at 10:53 PM, Leif Andersen  wrote:

> But `compile` is not supposed to evaluate any code, it just compiles
> it. Which is why it fails to compile that code. But if you interleave
> it with evals, it will run the require code, which gives the phase
> level 2 code some meaning.

I understand that `compile` isn't supposed to evaluate any _runtime_ code, but 
I thought it had to evaluate the compile-time code for it to compile the 
program?

Am I misunderstanding what `compile` is supposed to do? Or what compile-time 
code is, or?

> Does that make any sense, or was it too rambly.
> 
> ~Leif Andersen
> 
> 
> On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  wrote:
>> I get that `compile` doesn't evaluate the require form, but why doesn't it 
>> evaluate what's needed for compile time? I thought that was the reason for 
>> needing require as a macro instead of a function. Or am I getting the 
>> purpose of compile wrong?
>> 
>> Alex Knauth
>> 
>>> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
>>> 
>>> In the REPL, `begin` splices at the granularity of expansion and
>>> evaluation. That is, the first of the two forms grouped by `begin` is
>>> compiled and evaluated, and only afterward the second one is compiled
>>> and evaluated.
>>> 
>>> The `compile` function can't do that, because it's only supposed to
>>> compile -- not evaluate.
>>> 
>>> The `syntax/toplevel` library provides
>>> 
>>> expand-syntax-top-level-with-compile-time-evals
>>> 
>>> as an intermediate point between those: it pulls apart `begin` and
>>> `expands` (which is the interesting part of `compile`) the forms in
>>> sequence, but it evaluates only compile-time parts of the given forms.
>>> That works for many cases, including your example.
>>> 
>>> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
 So, I was under the impression that the REPL was the toplevel (unless
 you entered a module context or something like that). But I just had
 something challenge that assumption and so now I'm a bit confused.
 
 I have the following top level program:
 
 (begin
 (require (for-meta 1 racket)
  (for-meta 2 racket))
 (begin-for-syntax
   (begin-for-syntax
 (define x 5
 
 When I run this top level program in the REPL, it works just fine. And
 I can even reference x in later evaluations. (Provided I'm at the
 meta-level of 2).
 
 However, when I pass this top level program into compile like so:
 http://pasterack.org/pastes/38556
 
 (compile #'(begin
(require (for-meta 1 racket)
 (for-meta 2 racket))
(begin-for-syntax
  (begin-for-syntax
(define x 5)
 
 
 I get the following error:
 
 define: unbound identifier at phase 2;
 also, no #%app syntax transformer is bound in: define
 
 Can someone give me the reason (or at least some intuition) as to why
 this works in the repl, but not at the top level?
 
 Thank you.
 
 ~Leif Andersen
 
 --
 You received this message because you are subscribed to the Google Groups
 "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to racket-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
>>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>> 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Leif Andersen
So, the way I understand it (and please correct me if I'm wrong), is
that require is a macro for #%require, which is converted by the
compiler to either a top level require form, or part of the module's
require field. (Depending on where it goes).

When you put a `begin-for-syntax` or a `define-syntax` in your macro,
the bindings of each of the bodies need to become those of one phase
level up, which enables the macro expander to further expand the
macros in the expanded code. (This is better explained in the "You
Want it When" paper.
https://www.cs.utah.edu/plt/publications/macromod.pdf  )

The problem here is that by default, Racket only loads racket/base at
phase level 1, and no language at phase level 2, so racket/base must
be explicitly required to give anything two `begin-for-syntax` levels
in any meaning.

But `compile` is not supposed to evaluate any code, it just compiles
it. Which is why it fails to compile that code. But if you interleave
it with evals, it will run the require code, which gives the phase
level 2 code some meening.

Does that make any sense, or was it too rambly.

~Leif Andersen


On Mon, Dec 21, 2015 at 8:24 PM, Alex Knauth  wrote:
> I get that `compile` doesn't evaluate the require form, but why doesn't it 
> evaluate what's needed for compile time? I thought that was the reason for 
> needing require as a macro instead of a function. Or am I getting the purpose 
> of compile wrong?
>
> Alex Knauth
>
>> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
>>
>> In the REPL, `begin` splices at the granularity of expansion and
>> evaluation. That is, the first of the two forms grouped by `begin` is
>> compiled and evaluated, and only afterward the second one is compiled
>> and evaluated.
>>
>> The `compile` function can't do that, because it's only supposed to
>> compile -- not evaluate.
>>
>> The `syntax/toplevel` library provides
>>
>> expand-syntax-top-level-with-compile-time-evals
>>
>> as an intermediate point between those: it pulls apart `begin` and
>> `expands` (which is the interesting part of `compile`) the forms in
>> sequence, but it evaluates only compile-time parts of the given forms.
>> That works for many cases, including your example.
>>
>> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
>>> So, I was under the impression that the REPL was the toplevel (unless
>>> you entered a module context or something like that). But I just had
>>> something challenge that assumption and so now I'm a bit confused.
>>>
>>> I have the following top level program:
>>>
>>> (begin
>>>  (require (for-meta 1 racket)
>>>   (for-meta 2 racket))
>>>  (begin-for-syntax
>>>(begin-for-syntax
>>>  (define x 5
>>>
>>> When I run this top level program in the REPL, it works just fine. And
>>> I can even reference x in later evaluations. (Provided I'm at the
>>> meta-level of 2).
>>>
>>> However, when I pass this top level program into compile like so:
>>> http://pasterack.org/pastes/38556
>>>
>>> (compile #'(begin
>>> (require (for-meta 1 racket)
>>>  (for-meta 2 racket))
>>> (begin-for-syntax
>>>   (begin-for-syntax
>>> (define x 5)
>>>
>>>
>>> I get the following error:
>>>
>>> define: unbound identifier at phase 2;
>>> also, no #%app syntax transformer is bound in: define
>>>
>>> Can someone give me the reason (or at least some intuition) as to why
>>> this works in the repl, but not at the top level?
>>>
>>> Thank you.
>>>
>>> ~Leif Andersen
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Alex Knauth
I get that `compile` doesn't evaluate the require form, but why doesn't it 
evaluate what's needed for compile time? I thought that was the reason for 
needing require as a macro instead of a function. Or am I getting the purpose 
of compile wrong?

Alex Knauth

> On Dec 21, 2015, at 7:47 PM, Matthew Flatt  wrote:
> 
> In the REPL, `begin` splices at the granularity of expansion and
> evaluation. That is, the first of the two forms grouped by `begin` is
> compiled and evaluated, and only afterward the second one is compiled
> and evaluated.
> 
> The `compile` function can't do that, because it's only supposed to
> compile -- not evaluate.
> 
> The `syntax/toplevel` library provides
> 
> expand-syntax-top-level-with-compile-time-evals
> 
> as an intermediate point between those: it pulls apart `begin` and
> `expands` (which is the interesting part of `compile`) the forms in
> sequence, but it evaluates only compile-time parts of the given forms.
> That works for many cases, including your example.
> 
> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
>> So, I was under the impression that the REPL was the toplevel (unless
>> you entered a module context or something like that). But I just had
>> something challenge that assumption and so now I'm a bit confused.
>> 
>> I have the following top level program:
>> 
>> (begin
>>  (require (for-meta 1 racket)
>>   (for-meta 2 racket))
>>  (begin-for-syntax
>>(begin-for-syntax
>>  (define x 5
>> 
>> When I run this top level program in the REPL, it works just fine. And
>> I can even reference x in later evaluations. (Provided I'm at the
>> meta-level of 2).
>> 
>> However, when I pass this top level program into compile like so:
>> http://pasterack.org/pastes/38556
>> 
>> (compile #'(begin
>> (require (for-meta 1 racket)
>>  (for-meta 2 racket))
>> (begin-for-syntax
>>   (begin-for-syntax
>> (define x 5)
>> 
>> 
>> I get the following error:
>> 
>> define: unbound identifier at phase 2;
>> also, no #%app syntax transformer is bound in: define
>> 
>> Can someone give me the reason (or at least some intuition) as to why
>> this works in the repl, but not at the top level?
>> 
>> Thank you.
>> 
>> ~Leif Andersen
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Leif Andersen
Ah, okay, that makes sense. Thank you. I didn't realize begin was
evaluating each expression as it went.

Thank you.

~Leif Andersen


On Mon, Dec 21, 2015 at 5:47 PM, Matthew Flatt  wrote:
> In the REPL, `begin` splices at the granularity of expansion and
> evaluation. That is, the first of the two forms grouped by `begin` is
> compiled and evaluated, and only afterward the second one is compiled
> and evaluated.
>
> The `compile` function can't do that, because it's only supposed to
> compile -- not evaluate.
>
> The `syntax/toplevel` library provides
>
>  expand-syntax-top-level-with-compile-time-evals
>
> as an intermediate point between those: it pulls apart `begin` and
> `expands` (which is the interesting part of `compile`) the forms in
> sequence, but it evaluates only compile-time parts of the given forms.
> That works for many cases, including your example.
>
> At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
>> So, I was under the impression that the REPL was the toplevel (unless
>> you entered a module context or something like that). But I just had
>> something challenge that assumption and so now I'm a bit confused.
>>
>> I have the following top level program:
>>
>> (begin
>>   (require (for-meta 1 racket)
>>(for-meta 2 racket))
>>   (begin-for-syntax
>> (begin-for-syntax
>>   (define x 5
>>
>> When I run this top level program in the REPL, it works just fine. And
>> I can even reference x in later evaluations. (Provided I'm at the
>> meta-level of 2).
>>
>> However, when I pass this top level program into compile like so:
>> http://pasterack.org/pastes/38556
>>
>> (compile #'(begin
>>  (require (for-meta 1 racket)
>>   (for-meta 2 racket))
>>  (begin-for-syntax
>>(begin-for-syntax
>>  (define x 5)
>>
>>
>> I get the following error:
>>
>> define: unbound identifier at phase 2;
>>  also, no #%app syntax transformer is bound in: define
>>
>> Can someone give me the reason (or at least some intuition) as to why
>> this works in the repl, but not at the top level?
>>
>> Thank you.
>>
>> ~Leif Andersen
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Confused about the difference between the REPL and the toplevel.

2015-12-21 Thread Matthew Flatt
In the REPL, `begin` splices at the granularity of expansion and
evaluation. That is, the first of the two forms grouped by `begin` is
compiled and evaluated, and only afterward the second one is compiled
and evaluated.

The `compile` function can't do that, because it's only supposed to
compile -- not evaluate.

The `syntax/toplevel` library provides

 expand-syntax-top-level-with-compile-time-evals

as an intermediate point between those: it pulls apart `begin` and
`expands` (which is the interesting part of `compile`) the forms in
sequence, but it evaluates only compile-time parts of the given forms.
That works for many cases, including your example.

At Mon, 21 Dec 2015 17:35:22 -0700, Leif Andersen wrote:
> So, I was under the impression that the REPL was the toplevel (unless
> you entered a module context or something like that). But I just had
> something challenge that assumption and so now I'm a bit confused.
> 
> I have the following top level program:
> 
> (begin
>   (require (for-meta 1 racket)
>(for-meta 2 racket))
>   (begin-for-syntax
> (begin-for-syntax
>   (define x 5
> 
> When I run this top level program in the REPL, it works just fine. And
> I can even reference x in later evaluations. (Provided I'm at the
> meta-level of 2).
> 
> However, when I pass this top level program into compile like so:
> http://pasterack.org/pastes/38556
> 
> (compile #'(begin
>  (require (for-meta 1 racket)
>   (for-meta 2 racket))
>  (begin-for-syntax
>(begin-for-syntax
>  (define x 5)
> 
> 
> I get the following error:
> 
> define: unbound identifier at phase 2;
>  also, no #%app syntax transformer is bound in: define
> 
> Can someone give me the reason (or at least some intuition) as to why
> this works in the repl, but not at the top level?
> 
> Thank you.
> 
> ~Leif Andersen
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.