Happy friday all, what’s the recommended way to debug errors like this : with-syntax: binding match failed in: (LINE-FUNC)
The following clause is causing the error : (with-syntax* (....
[(LINE-FUNC) (format-id #'NUM "~a~a" "test" (syntax-e #'NUM))]))
[LINE-FUNC (format-id #'NUM "~a~a" "test" (syntax-e #'NUM)])
?
@soegaard2 that has too many () but is the right idea
Getting closer :slightly_smiling_face:
The return value of (format-id ...)
is a single value, so the pattern to the left must be a single identifier.
The pattern (LINE-FUNC)
matches a list of one element.
The error “binding match failed” says the pattern on the left didn’t match the value produced by the right hand side.
One way to debug is to print the result of the right hand side, and see if it returns what is expected.
Adding a couple of extra parenthesis there is easy to do - and can be hard to spot.
ah! fantastic!
Thanks for the answer and the debug tip
@michaelrauh has joined the channel
@i.am.corpix has joined the channel
Hello. I am try to understand whats going wrong with a dynamic-require
used outside of the REPL. I’ll describe details in a first message of this thread. Thanks in advance for the help
Here we have an example which works in REPL https://docs.racket-lang.org/reference/Module_Names_and_Loading.html?q=dynamic-require#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29
> (module a racket/base (displayln "hello"))
> (dynamic-require ''a #f)
hello
Same example is not working when running from the file(or via DrRacket “Run” button):
Welcome to fish, the friendly interactive shell
/h/user λ echo '#lang racket
(module a racket/base (displayln "hello"))
(dynamic-require \'\'a #f)' > dynamic-require.rkt
/h/user λ cat dynamic-require.rkt
#lang racket
(module a racket/base (displayln "hello"))
(dynamic-require ''a #f)
/h/user λ racket ./dynamic-require.rkt
instantiate: unknown module
module name: #<resolved-module-path:'a>
context...:
namespace-module-instantiate!
"/home/user/dynamic-require.rkt": [running body]
temp35_0
for-loop
run-module-instance!
perform-require!
I think the reason for this is same as for eval (initial namespace is empty) https://docs.racket-lang.org/guide/eval.html#%28part._namespaces%29
This fails because the initial current namespace is empty. When you run racket in interactive mode (see Interactive Mode), the initial namespace is initialized with the exports of the racket module, but when you run a module directly, the initial namespace starts empty.
But… I am expecting (module ...)
to register in the current namespace’s registry.
- Why is this happening? Does this have a simple explanation?
- What modifications should be performed to
dynamic-require
example to make it work outside the REPL?
I think someone replied this to you already?
The solution is to follow https://lists.racket-lang.org/users/archive/2013-May/058029.html
Use quote-module-path
At the REPL, you are not in any module
But in a #lang
file, you are
And (dynamic-require ''<something>)
doesn’t work inside a module.
I am new to this slack channel. I have asked similar question in the github issues, but been redirected here.
Ok, it works with quote-module-path
and your explanation makes sense. Thank you!