Fork me on GitHub
#clojurescript
<
2021-01-27
>
Adam Helins01:01:52

Here is something I have been fighting for hours. A brain twister I believe. Let us suppose 2 CLJC namespaces: 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 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 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.

Adam Helins01:01:19

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

Adam Helins01:01:50

TLDR ; How can a macro eval a form as Clojure in a Clojurescript project?

henryw37409:01:51

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.

Adam Helins10:01:13

Yes, however. When a macro in my.lib is called from , the value of *ns* is set to . That's great! The problem is that , 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 
  (:require [my.lib]))

(def foo 42)

(my.lib/some-evaling-macro (+ foo 1))
Because foo is undefined in the Clojure JVM world since has never been required. If I am talking gibberish I can write a proper gist but there is not much more to it.

henryw37410:01:28

I see now, thanks. Sorry I don't know how you could get something like that to work

sova-soars-the-sora02:01:14

There are reader conditionals

Mikko Harju08:01:44

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)

thheller09:01:20

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.

4
Mikko Harju09:01:25

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.

rberger08:01:35

Does anyone know of a current Clojurescript library or wrapper for working with webrtc?

takis_18:01:59

Hello, ide for clojurescript with javascript support also ? intellijidea community doesn't support javascript

takis_18:01:17

i was thinking to try atom,any suggestions ?

takis_18:01:09

i have ubuntu only i think visual studio works

takis_18:01:15

but not sure if all ok

takis_18:01:05

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

clyfe18:01:40

I use vscode on ubuntu and works

takis_18:01:35

good thank you i installed it again now

agold19:01:28

No problems here with vscode on Ubuntu.

joshmiller23:01:15

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.

thheller23:01:31

@joshmiller it does. as in (let [^Type foo (something)] ...)

joshmiller23:01:07

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.

thheller23:01:41

if that let is in a core.async go the typehint might get lost. core.async tends to lose that info.

joshmiller23:01:51

Ah, it was in a go block.

thheller23:01:59

yeah thats a bug

joshmiller23:01:08

Cool, good to know.