evyatar2013
2020-5-29 18:37:49

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))]))


soegaard2
2020-5-29 18:39:14

[LINE-FUNC (format-id #'NUM "~a~a" "test" (syntax-e #'NUM)])


soegaard2
2020-5-29 18:39:15

?


samth
2020-5-29 18:39:55

@soegaard2 that has too many () but is the right idea


soegaard2
2020-5-29 18:40:21

Getting closer :slightly_smiling_face:


soegaard2
2020-5-29 18:41:03

The return value of (format-id ...) is a single value, so the pattern to the left must be a single identifier.


soegaard2
2020-5-29 18:41:32

The pattern (LINE-FUNC) matches a list of one element.


soegaard2
2020-5-29 18:42:40

The error “binding match failed” says the pattern on the left didn’t match the value produced by the right hand side.


soegaard2
2020-5-29 18:43:13

One way to debug is to print the result of the right hand side, and see if it returns what is expected.


soegaard2
2020-5-29 18:44:32

Adding a couple of extra parenthesis there is easy to do - and can be hard to spot.


evyatar2013
2020-5-29 18:50:12

ah! fantastic!

Thanks for the answer and the debug tip


michaelrauh
2020-5-30 02:42:34

@michaelrauh has joined the channel


i.am.corpix
2020-5-30 05:08:57

@i.am.corpix has joined the channel


i.am.corpix
2020-5-30 05:22:34

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


i.am.corpix
2020-5-30 05:22:42

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.

  1. Why is this happening? Does this have a simple explanation?
  2. What modifications should be performed to dynamic-require example to make it work outside the REPL?

sorawee
2020-5-30 05:55:14

I think someone replied this to you already?


sorawee
2020-5-30 05:55:40

sorawee
2020-5-30 05:55:50

Use quote-module-path


sorawee
2020-5-30 05:56:16

At the REPL, you are not in any module


sorawee
2020-5-30 05:56:23

But in a #lang file, you are


sorawee
2020-5-30 05:56:50

And (dynamic-require ''<something>) doesn’t work inside a module.


i.am.corpix
2020-5-30 06:02:15

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!