Re: [racket-users] Re: questions about top-level-bind-scope in root-expand-context

2020-03-23 Thread Yongming Shen
Oops, I'm afraid things are getting off topic. Just to clarify, my question
is really as the title states, about top-level-bind-scope, which is used by
the expander to achieve certain effects when expanding
define-values/define-syntaxes forms at the top level. I'm mainly trying to
get a better understanding of those effects, and whether
top-level-bind-scope is necessary to implement them.

On Mon, Mar 23, 2020 at 8:11 PM Hendrik Boom  wrote:

> On Mon, Mar 23, 2020 at 05:55:14PM -0400, George Neuner wrote:
> > On Mon, 23 Mar 2020 16:57:26 -0400, Hendrik Boom
> >  wrote:
> >
> > >On Mon, Mar 23, 2020 at 02:46:53PM -0400, George Neuner wrote:
> > >> On Mon, 23 Mar 2020 01:45:40 -0700 (PDT), Yongming Shen
> > >>  wrote:
> > >>
> > >> >I have the following as `module-that-defines-fib`:
> > >> >
> > >> >  #lang racket
> > >> >  (provide fib)
> > >> >  (define fib "fib")
> > >> >
> > >> >And this is the error that I got (using Racket 7.6):
> > >> >
> > >> >  ; application: not a procedure;
> > >> >  ;  expected a procedure that can be applied to arguments
> > >> >  ;   given: "fib"
> > >> >  ; [,bt for context]
> > >>
> > >>
> > >> I've run into this problem before ... I don't recall the official
> > >> explanation, but my takeaway was that Racket does not permit you to
> > >> directly *export* a value - you have to export a function or macro
> > >> that produces the value.
> > >
> > >That seems like an extremely arbitrary restriction.
> >
> > Well, Racket considers exported objects to immutable.  You can export
> > a simple value (e.g., "foo" or 42) but it can only be used as a
> > constant.  If what you need is a module variable then the only way to
> > expose it is via an access function.
>
> That makes sense.
>
> Or I suppose you could build a one-element mtable array and export that.
> The you still can't change the variable, but can change teh value inside
> it.
>
> -- hendrik
> >
> > AFAIHS, the OP has not shown us the code which uses the provided
> > object, so we really don't know what it was trying to do when the
> > error occurred.
> >
> > George
> >
> > --
> > 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.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/p9bi7fpigiqm3tc3togm4vmontlv5v70ti%404ax.com
> .
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Racket Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/racket-users/7Y-a1r9oRPI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/20200324001128.u5rp6pw677lbhleg%40topoi.pooq.com
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAAFrGrSRHzqvZuX6QOYdYPrB54i%3D%3DOQzBGja8qXeaTNUfB9Syg%40mail.gmail.com.


Re: [racket-users] Re: questions about top-level-bind-scope in root-expand-context

2020-03-23 Thread Hendrik Boom
On Mon, Mar 23, 2020 at 05:55:14PM -0400, George Neuner wrote:
> On Mon, 23 Mar 2020 16:57:26 -0400, Hendrik Boom
>  wrote:
> 
> >On Mon, Mar 23, 2020 at 02:46:53PM -0400, George Neuner wrote:
> >> On Mon, 23 Mar 2020 01:45:40 -0700 (PDT), Yongming Shen
> >>  wrote:
> >> 
> >> >I have the following as `module-that-defines-fib`:
> >> >
> >> >  #lang racket
> >> >  (provide fib)
> >> >  (define fib "fib")
> >> >
> >> >And this is the error that I got (using Racket 7.6):
> >> >
> >> >  ; application: not a procedure;
> >> >  ;  expected a procedure that can be applied to arguments
> >> >  ;   given: "fib"
> >> >  ; [,bt for context]
> >> 
> >> 
> >> I've run into this problem before ... I don't recall the official
> >> explanation, but my takeaway was that Racket does not permit you to
> >> directly *export* a value - you have to export a function or macro
> >> that produces the value.
> >
> >That seems like an extremely arbitrary restriction.
> 
> Well, Racket considers exported objects to immutable.  You can export
> a simple value (e.g., "foo" or 42) but it can only be used as a
> constant.  If what you need is a module variable then the only way to
> expose it is via an access function.

That makes sense.

Or I suppose you could build a one-element mtable array and export that.
The you still can't change the variable, but can change teh value inside it.

-- hendrik
> 
> AFAIHS, the OP has not shown us the code which uses the provided
> object, so we really don't know what it was trying to do when the
> error occurred.
> 
> George
> 
> -- 
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/p9bi7fpigiqm3tc3togm4vmontlv5v70ti%404ax.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200324001128.u5rp6pw677lbhleg%40topoi.pooq.com.


[racket-users] Re: questions about top-level-bind-scope in root-expand-context

2020-03-23 Thread George Neuner
On Mon, 23 Mar 2020 16:57:26 -0400, Hendrik Boom
 wrote:

>On Mon, Mar 23, 2020 at 02:46:53PM -0400, George Neuner wrote:
>> On Mon, 23 Mar 2020 01:45:40 -0700 (PDT), Yongming Shen
>>  wrote:
>> 
>> >I have the following as `module-that-defines-fib`:
>> >
>> >  #lang racket
>> >  (provide fib)
>> >  (define fib "fib")
>> >
>> >And this is the error that I got (using Racket 7.6):
>> >
>> >  ; application: not a procedure;
>> >  ;  expected a procedure that can be applied to arguments
>> >  ;   given: "fib"
>> >  ; [,bt for context]
>> 
>> 
>> I've run into this problem before ... I don't recall the official
>> explanation, but my takeaway was that Racket does not permit you to
>> directly *export* a value - you have to export a function or macro
>> that produces the value.
>
>That seems like an extremely arbitrary restriction.

Well, Racket considers exported objects to immutable.  You can export
a simple value (e.g., "foo" or 42) but it can only be used as a
constant.  If what you need is a module variable then the only way to
expose it is via an access function.

AFAIHS, the OP has not shown us the code which uses the provided
object, so we really don't know what it was trying to do when the
error occurred.

George

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/p9bi7fpigiqm3tc3togm4vmontlv5v70ti%404ax.com.


Re: [racket-users] Re: questions about top-level-bind-scope in root-expand-context

2020-03-23 Thread Hendrik Boom
On Mon, Mar 23, 2020 at 02:46:53PM -0400, George Neuner wrote:
> On Mon, 23 Mar 2020 01:45:40 -0700 (PDT), Yongming Shen
>  wrote:
> 
> >Hi Matthew,
> >
> >Thank you for the quick reply!
> >
> >I tried the example you gave for my first question and it resulted in an 
> >error.
> >I have the following as `module-that-defines-fib`:
> >
> >  #lang racket
> >  (provide fib)
> >  (define fib "fib")
> >
> >And this is the error that I got (using Racket 7.6):
> >
> >  ; application: not a procedure;
> >  ;  expected a procedure that can be applied to arguments
> >  ;   given: "fib"
> >  ; [,bt for context]
> 
> 
> I've run into this problem before ... I don't recall the official
> explanation, but my takeaway was that Racket does not permit you to
> directly *export* a value - you have to export a function or macro
> that produces the value.

That seems like an extremely arbitrary restriction.

> 
> E.g., 
>   #lang racket
>   (provide fib)
>   (define (fib) "fib")
> 
> 
> >I think this is because `(define-values (x) ...)` expands `...` without the 
> >top-level-bind-scope, even when expand-context-to-parsed? is #t (according 
> >to expander/expand/top.rkt). Is this a bug?
> >Related to your answer to my second question, `define-syntaxes` similarly 
> >does not add the top-level-bind-scope when expanding `...`. Does this mean 
> >that even for `define-syntaxes`, `...` won't use the top-level-bind-scope 
> >binding(s) after all?
> >
> >A little bit off-topic, in the definition of define-values (in 
> >expander/expand/top.rkt), there is `(define-match m s ...)`, but for 
> >define-syntaxes it is `(define-match m disarmed-s ...)`. Is this difference 
> >significant? Or does define-match not care whether `s` or `disarmed-s` is 
> >used?
> 
> I don't know the internals so I can't evaluate your theory.
> 
> 
> >Thanks,
> >Yongming
> 
> George
> 
> -- 
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/2l0i7flr0to9msl6sg165vptiec0qq26l7%404ax.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200323205726.ccibywrggjxqticl%40topoi.pooq.com.


[racket-users] Re: questions about top-level-bind-scope in root-expand-context

2020-03-23 Thread George Neuner
On Mon, 23 Mar 2020 01:45:40 -0700 (PDT), Yongming Shen
 wrote:

>Hi Matthew,
>
>Thank you for the quick reply!
>
>I tried the example you gave for my first question and it resulted in an 
>error.
>I have the following as `module-that-defines-fib`:
>
>  #lang racket
>  (provide fib)
>  (define fib "fib")
>
>And this is the error that I got (using Racket 7.6):
>
>  ; application: not a procedure;
>  ;  expected a procedure that can be applied to arguments
>  ;   given: "fib"
>  ; [,bt for context]


I've run into this problem before ... I don't recall the official
explanation, but my takeaway was that Racket does not permit you to
directly *export* a value - you have to export a function or macro
that produces the value.

E.g., 
  #lang racket
  (provide fib)
  (define (fib) "fib")


>I think this is because `(define-values (x) ...)` expands `...` without the 
>top-level-bind-scope, even when expand-context-to-parsed? is #t (according 
>to expander/expand/top.rkt). Is this a bug?
>Related to your answer to my second question, `define-syntaxes` similarly 
>does not add the top-level-bind-scope when expanding `...`. Does this mean 
>that even for `define-syntaxes`, `...` won't use the top-level-bind-scope 
>binding(s) after all?
>
>A little bit off-topic, in the definition of define-values (in 
>expander/expand/top.rkt), there is `(define-match m s ...)`, but for 
>define-syntaxes it is `(define-match m disarmed-s ...)`. Is this difference 
>significant? Or does define-match not care whether `s` or `disarmed-s` is 
>used?

I don't know the internals so I can't evaluate your theory.


>Thanks,
>Yongming

George

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/2l0i7flr0to9msl6sg165vptiec0qq26l7%404ax.com.