Fork me on GitHub
#clojurescript
<
2023-06-21
>
Eric Scott15:06:55

So I'm having trouble using a custom tagged literal in a node repl. Tag reader works fine on the jvm side:

> #voc/dstr "1^^xsd:int"
#voc/dstr "1^^xsd:int"
But the same invocation in a node repl (cider/nrepl)
> #voc/dstr "1^^xsd:int"
Unexpected error (ExceptionInfo) compiling at (REPL:1).
failed compiling constant: 1; ont_app.vocabulary.dstr.DatatypeStr is not a valid ClojureScript constant.
Following the stack trace, this appears to be the :default for the cljs.compiler/emit-constant* method.
> (methods cljs.compiler/emit-constant*)
{nil #object[Function],
 ...
 ont-app.vocabulary.dstr/DatatypeStr #object[Function],
 ...
}
So it appears that the multimethod lookup is looking for ont_app.vocabulary.dstr.DatatypeStr, but what's being entered in the methods map is ont-app.vocabulary.dstr/DatatypeStr (differing on the underscore). Oh, this is not a problem when I use the command-line repl:
$ clj -M:test -m cljs.main
> (require '[ont-app.vocabulary.core :as voc])
> (def x #voc/dstr "1^^xsd:int")
> x
#voc/dstr "1^^xsd:int"
> (type x)
ont-app.vocabulary.dstr/DatatypeStr
> (type (voc/untag x))
#object[Number]
So is this a bug, or is there some configuration I'm not doing when I invoke my node/shadow-cljs/cider?

henryw37415:06:24

could be a few things...first though, have you read this? https://clojurescript.org/guides/reader

Eric Scott15:06:52

Yes, but let me re-read it.

henryw37415:06:24

so if I understand what you're saying, the problem is at the node repl, so there must be a clojurescript reader function that should be executing here. when at the cljs.main repl (`clj -M:test -m cljs.main`), that will be a clojure reader function - returning a valid clojurescript form. so quite different potentially

Eric Scott15:06:28

Here's my data_readers.cljc entry:

voc/dstr #?(:clj ont-app.vocabulary.dstr/read-DatatypeStr
                :cljs  ont-app.vocabulary.dstr/read-DatatypeStr-cljs
                :default ont-app.vocabulary.dstr/read-DatatypeStr
               )
Working off of these functions in the dstr.cljc file:
(defn read-DatatypeStr
  "Returns an instance of DatatypeStr parsed from `form`
  - Where:
  - `form` :- `str`^^`datatype`"
  ^DatatypeStr [form]
  yadda yadda)

(defn read-DatatypeStr-cljs
  "Returns a macro expression for read-DatatypeStr suitable for insertion and interpretation in cljs source."
  ^DatatypeStr [form]
  `(read-DatatypeStr ~form))

henryw37415:06:13

to recap - the node repl you're starting is something like clj -M -m cljs.main --repl-env node ? and you're saying that doesn't work, whereas the browser repl clj -M:test -m cljs.main does work? If so I'm at a loss as to what the issue might be

Eric Scott15:06:24

clj -M:test -m cljs.main --repl-env node seems to work as well.

Eric Scott16:06:01

Part of the problem is I don't play much on the cljs side.

henryw37416:06:12

so all good now ?

Eric Scott16:06:54

No, but it looks like we have a minimal pair between executing node in cider and executing node from the command line.

Eric Scott16:06:34

I guess I'll bring this up with the #C0617A8PQ channel and see what they think.