sorawee
2020-2-3 08:12:17

Thanks!


greg
2020-2-3 15:36:28

Today’s question: Given some string or symbol, how to create an identifier that identifier-binding will report is an existing module (not imported) binding in expanded syntax — and the module-path-index is actually the source file instead of #<module-path-index='\|expanded module\|> a.k.a. (module-path-index-join #f #f). https://gist.github.com/greghendershott/e94e4aee7cb3040f5332d0b0b80800e5


greg
2020-2-3 15:38:49

This isn’t urgent, for my immediate need I have a work-around that I don’t think is too hacky. But, after re-reading some reference materials about bindings, module bindings, expansion, syntax-binding-set, I’m kind of bothered that I can’t figure out how to make such an identifier. So, curious.


massung
2020-2-3 15:40:18

Just to understand completely, you mean across all (locally hosted) packages that may not be loaded as of yet?


greg
2020-2-3 15:41:28

Oh. For my immediate need, no. Just one specific file.


greg
2020-2-3 15:43:40

It’s not like identifier-binding is the only way to do this, with expanded syntax. You could just walk the syntax for define-values etc. It’s just, identifier-binding does give the correct answer when you’re in a module->namespace as opposed to merely expanded syntax. And, it would be handy (for me) if it behaved the same way. So I know ways to work around this.


greg
2020-2-3 15:46:44

I guess I’m curious why identifier-binding works one way with a module->namespace namespace, but another way with a namespace in which the syntax has been expanded. And what is the story about the module-path-index in the latter case? (The #<module-path-index='\|expanded module\|> a.k.a. (module-path-index-join #f #f)). Is that just some weird corner case and/or tiny buglet, or, does it reflect something about expansion and module bindings that I don’t know?


mflatt
2020-2-3 15:59:32

A module declaration that is expanded or compiled doesn’t yet have a name. The module declaration might even be evaluated multiple times with different names. Meanwhile, module->namespace always accesses a module that was created by evaluating a module declaration.


greg
2020-2-3 16:05:32

Ah, I see. That makes sense. Thanks!


greg
2020-2-3 16:19:43

I guess that also explains why I got the same result, even when I carefully found and extracted the exact piece of identifier syntax from the expanded syntax, and gave that to identifier-binding. Even with that lexical context, same result.


notjack
2020-2-3 16:41:18

> A module declaration that is expanded or compiled doesn’t yet have a name. The module declaration might even be evaluated multiple times with different names. > Wait, what? How do modules get their names?


mflatt
2020-2-3 17:00:23

A module gets a name via current-module-declare-name, which is set by things that evaluate module declarations, such as loading them from a file.


michaelmmacleod
2020-2-3 19:09:53

In the REPL when I type the following: > (define x 100) > (member x (namespace-mapped-symbols)) member is able to find x. But when I put the code into a file, member returns #f instead. Is there a way to get the REPL-like behavior in a file?



ben
2020-2-3 19:15:03

Those commands give me #f Welcome to Racket v7.6.0.9. > (define x 100) > (member x (namespace-mapped-symbols)) #f But I think you want to make a namespace for your file: #lang racket/base (define-namespace-anchor n) (define x 100) (and (member 'x (namespace-mapped-symbols (namespace-anchor->namespace n))) #t)


samth
2020-2-3 19:15:41

If you use 'x in the first one it will work


michaelmmacleod
2020-2-3 19:19:14

Thanks! I’ll have to do some reading namespace anchors. edit: oops, samth’s comment made me realize that I typed x instead of (what I meant),'x .


notjack
2020-2-3 20:15:16

Yeah that’s not great