Re: [racket-users] namespace-variable-value thinks functions are bound to syntax

2017-10-31 Thread Junsong Li
That works! Thanks.

On Mon, Oct 30, 2017 at 9:35 AM Shu-Hung You <
shu-hung@eecs.northwestern.edu> wrote:

> Yes, because keyword functions expand to macro definitions that try to
> optimize keyword applications.
>
> namespace-require and namespace-variable-value are relatively
> low-level operations on modules and namespaces. Using dynamic-require
> could be a bit easier:
>
> #lang racket
>
> (module p racket
>   (provide (all-defined-out))
>
>   (define (foo0 a b)
> (+ a b))
>   (define (foo1 a b [c 3])
> (+ a b c))
>   (define (foo2 a b [c 3] #:kw1 kw1)
> (+ a b c))
>   (define (foo3 a b [c 3] #:kw1 kw1 #:kw2 [kw2 1])
> (+ a b c))
>   )
>
> (require syntax/location)
>
> (define ns (make-base-empty-namespace))
>
> (parameterize ([current-namespace ns])
>   (dynamic-require (quote-module-path p) 'foo0))
> ;=> #
>
> (parameterize ([current-namespace ns])
>   (dynamic-require (quote-module-path p) 'foo1))
> ;=> #
>
> (parameterize ([current-namespace ns])
>   (dynamic-require (quote-module-path p) 'foo2))
> ;=> #
>
> (parameterize ([current-namespace ns])
>   (dynamic-require (quote-module-path p) 'foo3))
> ;=> #
>
> Please note that dynamic-require handles macro exports specially, as
> stated in the doc:
>
>
> https://docs.racket-lang.org/reference/Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29
> > If the module exports _provided_ as syntax,
> > then a use of the binding is expanded and
> > evaluated in a fresh namespace to which
> > the module is attached, which means that
> > the module is visited in the fresh namespace.
> > The expanded syntax must return a single value.
>
> Best,
> Shu-Hung
>
> On Sun, Oct 29, 2017 at 7:40 PM, Junsong Li 
> wrote:
> > Hello list,
> >
> > In the following program, racket thinks foo2, and foo3 are bound to
> > syntax. Is this expected behavior?
> >
> > -- File: go.rkt
> >
> > #lang racket
> >
> > (module p racket
> >   (provide (all-defined-out))
> >
> >   (define (foo0 a b)
> > (+ a b))
> >   (define (foo1 a b [c 3])
> > (+ a b c))
> >   (define (foo2 a b [c 3] #:kw1 kw1)
> > (+ a b c))
> >   (define (foo3 a b [c 3] #:kw1 kw1 #:kw2 [kw2 1])
> > (+ a b c))
> >   )
> >
> > (require syntax/location)
> >
> > (define ns (make-base-empty-namespace))
> > (parameterize ([current-namespace ns])
> >   (namespace-require (quote-module-path p)))
> >
> > (namespace-variable-value 'foo0 #t #f ns) ; OK
> > (namespace-variable-value 'foo1 #t #f ns) ; OK
> > (namespace-variable-value 'foo2 #t #f ns) ; namespace-variable-value:
> > bound to syntax in: foo2
> > (namespace-variable-value 'foo3 #t #f ns) ; namespace-variable-value:
> > bound to syntax in: foo3
> >
> > --
> > 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.


[racket-users] namespace-variable-value thinks functions are bound to syntax

2017-10-29 Thread Junsong Li
Hello list,

In the following program, racket thinks foo2, and foo3 are bound to
syntax. Is this expected behavior?

-- File: go.rkt

#lang racket

(module p racket
  (provide (all-defined-out))

  (define (foo0 a b)
(+ a b))
  (define (foo1 a b [c 3])
(+ a b c))
  (define (foo2 a b [c 3] #:kw1 kw1)
(+ a b c))
  (define (foo3 a b [c 3] #:kw1 kw1 #:kw2 [kw2 1])
(+ a b c))
  )

(require syntax/location)

(define ns (make-base-empty-namespace))
(parameterize ([current-namespace ns])
  (namespace-require (quote-module-path p)))

(namespace-variable-value 'foo0 #t #f ns) ; OK
(namespace-variable-value 'foo1 #t #f ns) ; OK
(namespace-variable-value 'foo2 #t #f ns) ; namespace-variable-value:
bound to syntax in: foo2
(namespace-variable-value 'foo3 #t #f ns) ; namespace-variable-value:
bound to syntax in: foo3

-- 
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] namespace-require a submodule

2017-10-29 Thread Junsong Li
That explains. Thanks!

On Sun, Oct 29, 2017 at 11:20 AM, Sam Tobin-Hochstadt
 wrote:
> If you look at what `(quote-module-path food)` produces, it's just
> `(submod "/path/to/go.rkt" food)`. The issue is just that
> `namespace-require` needs a reference that it can resolve without
> knowing what file it's in -- `namespace-require`, unlike `require`, is
> a just a function and doesn't know anything about where it is in the
> source code. So you need to use something like `(quote-module-path)`
> that knows where it is.
>
> Sam
>
> On Sun, Oct 29, 2017 at 2:12 PM, Junsong Li  wrote:
>> Thanks! That works.
>>
>> I am still not sure what is the thing that I don't know. Why do we need a
>> compile-time reference here?
>>
>> On Sun, Oct 29, 2017 at 9:59 AM, Sam Tobin-Hochstadt 
>> wrote:
>>>
>>> I think you want to use `quote-module-path` here:
>>>
>>> #lang racket
>>>
>>> (require syntax/location)
>>>
>>> (module food racket
>>>   (provide apple)
>>> (define apple "pie"))
>>>
>>> (parameterize ([current-namespace (make-base-namespace)])
>>>   (namespace-require (quote-module-path food))
>>> (eval 'apple))
>>>
>>> On Sun, Oct 29, 2017 at 12:19 PM, Junsong Li 
>>> wrote:
>>> > Hello list,
>>> >
>>> > I am trying to do namespace-require to a submodule, racket complains
>>> > about
>>> > unknown module, as below:
>>> >
>>> > $ cat go.rkt
>>> > #lang racket
>>> >
>>> > (module food racket
>>> >   (provide apple)
>>> > (define apple "pie"))
>>> >
>>> > (parameterize ([current-namespace (make-base-namespace)])
>>> >   (namespace-require ''food)
>>> > (eval 'apple))
>>> >
>>> > $ racket go.rkt
>>> > require: unknown module
>>> >   module name: #
>>> >   context...:
>>> >
>>> >
>>> > Simply namespace-require food in toplevel has the same issue:
>>> >
>>> > #lang racket
>>> >
>>> > (module food racket
>>> >   (provide apple)
>>> > (define apple "pie"))
>>> >
>>> > (namespace-require ''food)
>>> >
>>> > Finally, the above code works if I type them in the interactive mode.
>>> >
>>> > I tried namespace-attach-module, and I understand why that failed: it
>>> > didn't
>>> > work because (module food racket ...) wouldn't instantiate the module,
>>> > and a
>>> > instantiated module is what namespace-attach-module wants.
>>> >
>>> > What is it that I am missing in above code to require a submodule in a
>>> > namespace? Why is submodule food invisible here?
>>> >
>>> >
>>> > - Junsong
>>> >
>>> > --
>>> > 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] namespace-require a submodule

2017-10-29 Thread Junsong Li
Thanks! That works.

I am still not sure what is the thing that I don't know. Why do we need a
compile-time reference here?

On Sun, Oct 29, 2017 at 9:59 AM, Sam Tobin-Hochstadt 
wrote:

> I think you want to use `quote-module-path` here:
>
> #lang racket
>
> (require syntax/location)
>
> (module food racket
>   (provide apple)
> (define apple "pie"))
>
> (parameterize ([current-namespace (make-base-namespace)])
>   (namespace-require (quote-module-path food))
> (eval 'apple))
>
> On Sun, Oct 29, 2017 at 12:19 PM, Junsong Li 
> wrote:
> > Hello list,
> >
> > I am trying to do namespace-require to a submodule, racket complains
> about
> > unknown module, as below:
> >
> > $ cat go.rkt
> > #lang racket
> >
> > (module food racket
> >   (provide apple)
> > (define apple "pie"))
> >
> > (parameterize ([current-namespace (make-base-namespace)])
> >   (namespace-require ''food)
> > (eval 'apple))
> >
> > $ racket go.rkt
> > require: unknown module
> >   module name: #
> >   context...:
> >
> >
> > Simply namespace-require food in toplevel has the same issue:
> >
> > #lang racket
> >
> > (module food racket
> >   (provide apple)
> > (define apple "pie"))
> >
> > (namespace-require ''food)
> >
> > Finally, the above code works if I type them in the interactive mode.
> >
> > I tried namespace-attach-module, and I understand why that failed: it
> didn't
> > work because (module food racket ...) wouldn't instantiate the module,
> and a
> > instantiated module is what namespace-attach-module wants.
> >
> > What is it that I am missing in above code to require a submodule in a
> > namespace? Why is submodule food invisible here?
> >
> >
> > - Junsong
> >
> > --
> > 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.


[racket-users] namespace-require a submodule

2017-10-29 Thread Junsong Li
Hello list,

I am trying to do namespace-require to a submodule, racket complains about
unknown module, as below:

$ cat go.rkt
#lang racket

(module food racket
  (provide apple)
(define apple "pie"))

(parameterize ([current-namespace (make-base-namespace)])
  (namespace-require ''food)
(eval 'apple))

$ racket go.rkt
require: unknown module
  module name: #
  context...:


Simply namespace-require food in toplevel has the same issue:

#lang racket

(module food racket
  (provide apple)
(define apple "pie"))

(namespace-require ''food)

Finally, the above code works if I type them in the interactive mode.

I tried namespace-attach-module, and I understand why that failed: it
didn't work because (module food racket ...) wouldn't instantiate the
module, and a instantiated module is what namespace-attach-module wants.

What is it that I am missing in above code to require a submodule in a
namespace? Why is submodule food invisible here?


- Junsong

-- 
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.


[racket-users] BSL expansion

2015-05-22 Thread Junsong Li
Hello list,

I am wondering how to expand a BSL program into the Racket _core language_?
Let's say a simple program:

(define (id x) x)

Thanks.

-- 
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.