Re: [racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Shriram Krishnamurthi
Ooh, thank you Oak and Jens Axel! I would never have figured that out.

As Matthew's email from Jan 2020 says, having the documentation say
something (and, in particular, suggesting the use of `parameterize` to get
what many users might expect) would be quite lovely.

(Thanks also, Greg.)

Shriram

-- 
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/CAJUf2yQsm_w2JmSVO%3D8x9-JuepRGbpEDqyrsJxi2PVKZDCmVYw%40mail.gmail.com.


Re: [racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Jens Axel Søgaard
Den tir. 21. jul. 2020 kl. 20.25 skrev Sorawee Porncharoenwase <
sorawee.pw...@gmail.com>:

> This is weird. I usually parameterize current-namespace when using
> namespace-* functions, and in this particular case it works fine.
>
> On Tue, Jul 21, 2020 at 11:05 AM Shriram Krishnamurthi 
> wrote:
>
>> Thank you! Would you know why I might get this error:
>>
>> ; require: unknown module
>>
>> ;   module name:
>>
>> ; #>
>>
>> (This is from inside a module.)
>>
>> Trying the same at the REPL, I see the same thing:
>>
>> > (define n (make-base-namespace))
>>
>> > (namespace-require `(file ,(path->string (build-path "wheats"
>> "w1.rkt"
>>
>> [note no optional namespace]
>> works fine; the name is available at the top-level; but using the same
>> pathname but with the namespace parameter:
>>
>> > (namespace-require `(file ,(path->string (build-path "wheats"
>> "w1.rkt"))) n)
>>
>> ; require: unknown module
>>
>> ;   module name:
>>
>> ; #>
>>
>> (The file in question begins with #lang racket.)
>>
>>

#lang racket

(define ns (make-base-namespace))
(define p  (build-path "/Users/soegaard/tmp" "w1.rkt"))

(parameterize ([current-namespace ns])
  (namespace-require p))

I had to dig up

https://www.mail-archive.com/racket-users@googlegroups.com/msg43291.html

to figure it out.

/Jens Axel

-- 
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/CABefVgyYCFn8%3DVF8Ufr4Q_vwt2nKiTnnk-0t24%3DA%3DmxcSYkKNw%40mail.gmail.com.


Re: [racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Sorawee Porncharoenwase
This is weird. I usually parameterize current-namespace when using
namespace-* functions, and in this particular case it works fine.

On Tue, Jul 21, 2020 at 11:05 AM Shriram Krishnamurthi 
wrote:

> Thank you! Would you know why I might get this error:
>
> ; require: unknown module
>
> ;   module name:
>
> ; #>
>
> (This is from inside a module.)
>
> Trying the same at the REPL, I see the same thing:
>
> > (define n (make-base-namespace))
>
> > (namespace-require `(file ,(path->string (build-path "wheats"
> "w1.rkt"
>
> [note no optional namespace]
> works fine; the name is available at the top-level; but using the same
> pathname but with the namespace parameter:
>
> > (namespace-require `(file ,(path->string (build-path "wheats"
> "w1.rkt"))) n)
>
> ; require: unknown module
>
> ;   module name:
>
> ; #>
>
> (The file in question begins with #lang racket.)
>
> Shriram
>
> --
> 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/CAJUf2yQijBugL3PBo%2B5SBj-9zEKnUc2ejH52VB0AkTW%3DniRGQw%40mail.gmail.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/CADcuegugFPk2KjHF%3D550%3Dv5dzs1XD74z-mfJWBwBMmC1AtxSzg%40mail.gmail.com.


Re: [racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Shriram Krishnamurthi
Thank you! Would you know why I might get this error:

; require: unknown module

;   module name:

; #>

(This is from inside a module.)

Trying the same at the REPL, I see the same thing:

> (define n (make-base-namespace))

> (namespace-require `(file ,(path->string (build-path "wheats" "w1.rkt"

[note no optional namespace]
works fine; the name is available at the top-level; but using the same
pathname but with the namespace parameter:

> (namespace-require `(file ,(path->string (build-path "wheats" "w1.rkt")))
n)

; require: unknown module

;   module name:

; #>

(The file in question begins with #lang racket.)

Shriram

-- 
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/CAJUf2yQijBugL3PBo%2B5SBj-9zEKnUc2ejH52VB0AkTW%3DniRGQw%40mail.gmail.com.


Re: [racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Jens Axel Søgaard
Den tir. 21. jul. 2020 kl. 17.45 skrev Shriram Krishnamurthi <
shri...@gmail.com>:

> How I can combine these three? I want to do something like this:
>
> (define n (make-base-namespace))
> (define p (build-path f))
> (eval `(require ,p) n)
>
> Racket doesn't like that: bad syntax for require sub-form because p is a
> path-typed value.
>
> Essentially, I want to inject the module at f into n so that the provided
> identifiers of f are visible inside n. (I haven't been able to get
> dynamic-require working either, nor is it an entirely satisfactory
> solution because I may not always know what names f is providing.)
>

Sounds like a job for `namespace-require` with a require spec of the form
`(file ,(path->string (build-path f)))`.

/Jens Axel

-- 
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/CABefVgzwBhd%3D27JCRr3PDj5NKL8iukiQCsEspww%2BTBcPBUe4dQ%40mail.gmail.com.


[racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Shriram Krishnamurthi
How I can combine these three? I want to do something like this:

(define n (make-base-namespace))
(define p (build-path f))
(eval `(require ,p) n)

Racket doesn't like that: bad syntax for require sub-form because p is a 
path-typed value.

Essentially, I want to inject the module at f into n so that the provided 
identifiers of f are visible inside n. (I haven't been able to get 
dynamic-require working either, nor is it an entirely satisfactory solution 
because I may not always know what names f is providing.)

Thanks,
Shriram

-- 
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/978e4a26-d7fc-4e5d-aabe-6464a3181420n%40googlegroups.com.