Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
edited by

as the title suggests, def appears to pass through without doing anything.

i.e. "(def x)" succeeds
but "(def x 10)" fails because
"Cannot read properties of undefined (reading 'x')"

article here: https://clojurescript.org/guides/self-hosting

suggests :simple optimization should work

to reproduce: https://github.com/sstraust/ClojureDefRepro (see comments for instructions)

by
Perhaps it would help if you could create a repo with a script that you can run to reproduce this. This would save time for the person who is going to look into this.
by
hi! attached is a github repository that reproduces the error.
you can see the error by:

- opening the top-level index.html file
- and then calling "example.core.call_eval_with_def()" from the javascript console.

https://github.com/sstraust/ClojureDefRepro

Included in the repo is a screenshot of my javascript console containing the resulting error.

thanks! -- sammy

1 Answer

+1 vote
by
selected by
 
Best answer

I didn't run the code, but my guess is that the code is compiled to emit

cljs.user.x = 10;

with cljs.user not being defined yet. Thus it fails when you try to run this since it tries to set x on cljs.user. Try creating cljs.user first, or by supplying an already existing :ns option when compiling.

by
WOW! this does work

adding (ns cljs.user) appears to have fixed the issue.

Interestingly I had already tried explicitly passing a :ns option, but I wasn't able to get that working. might be my own user error though
...