This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-06
Channels
- # announcements (33)
- # babashka (13)
- # babashka-sci-dev (23)
- # beginners (94)
- # calva (105)
- # cider (37)
- # circleci (1)
- # clj-kondo (45)
- # cljs-dev (59)
- # cljsrn (2)
- # clojure (145)
- # clojure-czech (1)
- # clojure-europe (19)
- # clojure-nl (18)
- # clojure-norway (13)
- # clojure-portugal (1)
- # clojure-uk (5)
- # clojurescript (19)
- # community-development (2)
- # conjure (3)
- # copenhagen-clojurians (1)
- # core-async (34)
- # data-science (6)
- # datomic (25)
- # emacs (43)
- # fulcro (19)
- # graalvm (7)
- # graalvm-mobile (12)
- # graphql (10)
- # honeysql (3)
- # hyperfiddle (3)
- # improve-getting-started (2)
- # interop (20)
- # kaocha (3)
- # lsp (16)
- # meander (7)
- # off-topic (22)
- # other-languages (14)
- # portal (15)
- # releases (1)
- # rewrite-clj (2)
- # ring (1)
- # shadow-cljs (119)
- # spacemacs (19)
- # sql (65)
- # testing (4)
- # tools-deps (11)
- # xtdb (29)
I'm having troubles in self-hosted ClojureScript with multi-arity macros. Are there any known issues about this? The only output I'm getting is:
Execution error (Error) at (<cljs repl>:1).
Invalid arity: 0
without any line numbers. The macros work perfectly in "normal" CLJSThis is a repro: https://github.com/babashka/sci/commit/e73377fc37972d0661509a68678961926ba7acf5
Here is a smaller repro:
(ns sci.repro
#?(:cljs (:require-macros [sci.repro :refer [ma-macro]])))
(defmacro ma-macro
([x] `(ma-macro ~x 1))
([x y] `(+ ~x ~y)))
(ma-macro 1)
cljs.user=> (require '[sci.repro])
Execution error (Error) at (<cljs repl>:1).
Invalid arity: -1
how do you feel about if we move the actual impl to a multi-arity function and make the macro body an apply
call?
(defn ma-macro*
([x] (ma-macro* x 1))
([x y] `(+ ~x ~y)))
(defmacro ma-macro
([x & args] (apply ma-macro* x args )))
Not a fan of that. Also not sure if what would work since there's a reason why things are macros. If it could have been done using a function we probably would have already
@U013JFLRFS8 But your suggestion does seem to work in general: Using:
[sym ns & [opts]]
as the arg vector also fixes the problem!cool - I'm bouncing back and forth between this and making it look like I'm doing my job, so it might be a little while before I update the PR (you might already be done for the night because timezones)
I wonder if we should treat :name
as a compile time constant, similar to the first argument:
(sci/copy-var inc nil {:name 'foo})
vs:
(sci/copy-var inc nil {:name foo})
just a wild guess but could be that ma-macro
is just resolved to the local sci.repro/ma-macro
instead of the sci.repro$macros/ma-macro
. In shadow-cljs I made regular defmacro
not emit anything when not in "macros" compilation mode. That at least prevented confusing error messages such as this one.
by moving it to a separate file you basically remove sci.repro/ma-macro
and only sci.repro$macros/ma-macro
will exist
could also just be the problem with the top level call. since both the macro variant and the normal variant will call this. it one of those versions it won't exist
@thheller I hoped to avoid that by using macros/deftime
(borrowed from @cgrand’s macrovich)
https://github.com/babashka/sci/commit/e73377fc37972d0661509a68678961926ba7acf5#diff-faebb48a23c0728ab5401da8d8a73473dfb546b9c04cf37f0913fc731f7a725eL50
but it seems it doesn't work for multi-arity macros somehow
Here's the definition: https://github.com/babashka/sci/blob/9b5f8eb83d859fe4f7f098aa242e70809b43be15/src/sci/impl/macros.cljc#L6
But this both prints true even when I wrap that macro:
#?(:cljs (prn (exists? repro.ma-macro)))
#?(:cljs (prn (exists? repro$macros.ma-macro)))
This is also surprising:
(ns repro
#?(:cljs (:require-macros [repro :refer [ma-macro]])))
(defmacro ma-macro
#_([x] `(ma-macro ~x 1))
([x y] `(+ ~x ~y)))
(prn (ma-macro 1 2)) ;;=> (cljs.core/+ nil nil)
should have read more carefully, first. Last time we tried self-hosted an ran into issues with with getting the reagent/with-let
macro to work with selfhost we ended up filing
• https://clojure.atlassian.net/browse/CLJS-3286
• https://clojure.atlassian.net/browse/CLJS-3287
• https://clojure.atlassian.net/browse/CLJS-3288
of which only CLJS-3287
is fixed on main
if I read things correctly. So I thought there might be a connection but your problem does look different.
I've ran into this problem before and then I decided to just split the macro into a separate macro for each arity...
In a recent release I forgot to check compatibility with self-hosted but someone filed an issue about this, since they used self-hosted to test their lib + SCI
but now we're trying to add an option map to an existing macro and running into this stuff again
@mkvlr it wasn't on my radar there were updated patches for those, trying them out now
@quoll finally looked over the math stuff, generally looks ok - I think the only thing is that we have communicate this will only work in JS environments w/ typed array support - for most folks not a big deal
We discussed this a few months ago. I just don't have any way to get from bits back into a double without using a typed array. Luckily, they're reasonably ubiquitous now. A note on the release makes sense
I am working on improving random-uuid and need typed arrays for that too. Should this be perhaps a runtime check and produce some kind of warning?
I'm in favor of this, though this is exactly the sort of thing that is up to David. It need only Show up when requiring namespaces that need this, right? So, ideally, anyone trying to use ClojureScript on a system without typed arrays would not see a warning until they tried to load the ns
one thing I noticed is that there is still references to Double
copied from the Clojure docstrings - this is not a big deal either - could merge and let people kick it around and could take a patch to fix that stuff up
sure go for it, happy to get this pushed through since I've stalled on it for so long 🙂
@quoll is this one ready? https://clojure.atlassian.net/browse/CLJS-3348
Perhaps the uuid regex could be improved:
(def hex-regex
"Regex matching to a UUID in hexadecimal form, e.g., 0713d2bf-8e70-41e2-8b81-c8ca3ef4a8cd."
#"^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[4][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$")
Matching other letters than A-F and a-f doesn't make any sense in my opinion. Not using the multiplicative brackets makes the whole thing really verbose. Do I miss something? We use it at OrgPad just fine.I have a version where I used the multiplicative braces, so I don’t know why I checked that in. I need to check what I did when I can