Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requiring macro via load-file fails in the REPL if the macro is in top level namespace #1059

Open
PEZ opened this issue Nov 1, 2022 · 1 comment

Comments

@PEZ
Copy link

PEZ commented Nov 1, 2022

From this discussion in Slack.

Following this example, for how to work with macros in ClojureScript, fails in the REPL if I define the macro in a top-level namespace:

util.clj:

(ns util)

(defmacro foo [& body]
  (apply str body))

util.cljs:

(ns util
  (:require-macros [util]))

my/app.cljs:

(ns my.app
  (:require [util]))

(print (util/foo 1 2 3))

If I now load the my/app.cljs file, I now should be able to use the macro, and expect it to print 123 when it is loaded, but it fails on the first load, and starts to work if I load the file again:

% npx shadow-cljs node-repl
shadow-cljs - config: /Users/pez/Projects/sass2garden/shadow-cljs.edn
[2022-11-01 23:41:15.678 - WARNING] TCP Port 9630 in use.
[2022-11-01 23:41:15.681 - WARNING] TCP Port 9631 in use.
shadow-cljs - server version: 2.20.7 running at http://localhost:9632
shadow-cljs - nREPL server started on port 58439
(lcljs.user=> oshadow-cljs - #4 ready!
ad-file "src/main/my/app.cljs")
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: <eval>:4:9
 Use of undeclared Var util/foo
--------------------------------------------------------------------------------

cljs.user=> (load-file "src/main/my/app.cljs")
123
[]
cljs.user=> 

However, if I place the macro in my.util, things work as expected.

Please note, @thheller, that (require 'my.app) works. My repro in that Slack conversation was crap. This seems to be with load-file.

@thheller
Copy link
Owner

thheller commented Nov 2, 2022

I can reproduce the problem when using load-file and your "flat" namespaces. I can also reproduce moving the namespaces to a proper structure (ie. no single-segment namespaces, util becomes my.util) working just fine. Not yet sure why though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants