Here is something I have been fighting for hours. A brain twister I believe.
Let us suppose 2 CLJC namespaces: <http://my.app|my.app>
figures in a Clojurescript project while ns.lib
is a library providing a macro. This macro takes a form which needs to be evaled. In theory, it's fine: that form comes from <http://my.app|my.app>
and can be consumed both from Clojure JVM and Clojurescript.
Here is the catch: evaling that form in the macro fails. I guess that while <http://my.app|my.app>
has been interpreted as a Clojurescript file, it has not been interpreted as a Clojure JVM one and what the macros sees (from a "Clojure JVM point of view") is an empty namespace. As such, evaling fails as soon as this form contains a defined sym or something that is required.
Using (require)
in the macro produces weird undefined-looking behavior. I guess this is because it induces a circular dependency (`http://my.app` using a macro from ns.lib
which then needs to dynamically require <http://my.app|my.app>
).
TLDR ; How can a macro eval a form as Clojure in a Clojurescript project?
hmm, maybe a gist would help. macros are clojure code that return forms which are read by the clojurescript compiler. so bc they are clojure code, you can do any clojure stuff you want, including eval.
Yes, however. When a macro in my.lib
is called from <http://my.app|my.app>
, the value of *ns*
is set to <http://my.app|my.app>
. That's great! The problem is that <http://my.app|my.app>
, being in a CLJC file, has been loaded as Clojurescript whereas in the macro we are in the Clojure JVM world. So this fails:
(ns <http://my.app|my.app>
(:require [my.lib]))
(def foo 42)
(my.lib/some-evaling-macro (+ foo 1))
Because foo
is undefined in the Clojure JVM world since <http://my.app|my.app>
has never been required.
If I am talking gibberish I can write a proper gist but there is not much more to it.I see now, thanks. Sorry I don't know how you could get something like that to work
Interesting, I don't really know lit-html but after reading more about it I am wondering if CLJS could do all the preparations lit-html does in mere macros.
There are reader conditionals
but that's .cljc
Hi! Trying to get re-natal/figwheel based React Native project up and running again using the newest RN + CLJS -combination. I'm basically stuck in a point where cljs_deps.js
does a goog.addDependency("math/long.js", ['goog.math.Long'], ['goog.asserts', 'goog.reflect']);
that is converted to a TransformedDependency
. It calls out to CLOSURE_LOAD_FILE_SYNC
that is supposed to load the file synchronously in order for it to get transformed. Do I really need to create a native extension function to handle synchronous loading for this or how does e.g. shadow-cljs handle the initial loading of all the files? The CLOSURE_IMPORT_SCRIPT
side is working just fine since its async, but that math/long.js -transformation step fails the loading of cljs_deps (it does not continue loading the other requirements that come after that definition)
Does anyone know of a current Clojurescript library or wrapper for working with webrtc
?
shadow-cljs does not use the "debug loader" mechanism of the closure library. therefore it doesn't do the goog.addDependency
or any of the CLOSURE_IMPORT
stuff. for react-native stuff it just emits the files that needs to be loaded into the .js
file as strings and then evals them on load. it could just emit the files directly without that indirection too but I'm trying to "hide" the code from metro
so it doesn't try to process it. makes things faster and more reliable overall.
Thanks for the answer! I managed to fix this for now by making a faux sync loader that returns an empty object that then makes the goog debug loader to believe it has done its job 😄 I might be transforming the project to shadow-cljs react-native toolkit, but now is not the time to do that since this is a fairly large project and fixing the requirements is not a trivial task.
Hello, ide for clojurescript with javascript support also ? intellijidea community doesn't support javascript
i was thinking to try atom,any suggestions ?
i have ubuntu only i think visual studio works
but not sure if all ok
i tried it in past i had some problems and went to intellijdea again , i think i wwill just try them all again , thank you
I use vscode on ubuntu and works
good thank you i installed it again now
No problems here with vscode on Ubuntu.
I recently needed to type hint an object from a library being loaded from an external source to get advanced compilation working. I first tried hinting it in a let-block, but that didn’t work. Then I extracted it into a function and hinted the argument and that did. Is that expected cljs behavior? The Clojure guide for Java interop says let-blocks are available type hinting locations, but I don’t know if that extends to cljs or not.
@joshmiller it does. as in (let [^Type foo (something)] ...)
Hm, ok, not sure what my issue was then. I’ll see if I can make a minimal reproduction for either a bug or to see what I did wrong.
if that let is in a core.async go the typehint might get lost. core.async tends to lose that info.
Ah, it was in a go
block.
yeah thats a bug
Cool, good to know.