This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
I wrote a cljc macro to create and reify setter protocols for my type definition's mutable fields. I have a predicate that pulls out the mutable fields based on the metadata. However, in the :cljs
part of the reader conditional never seems to see the metadata, only the :clj
part see's the ^:mutable
metadata. Is that suppose to happen? When do type hints get evaluated/read?
I mean I guess it's a reader thing because of the ^
character, but shouldn't it still appear in the :cljs
branch of the reader conditional?
Not entirely clear what you're doing. But if you're using a reader conditional in a macro, it will always use the :clj
branch since macros are executed by the compiler on the CLJ side (unless it's self-hosted CLJS).
This is what I thought. :thinking_face:
Will post code, give me a second.
@U2FRKM4TW https://github.com/janetacarr/match-set-and-get/blob/main/src/match_set_and_get/core.cljc
Why not just a .clj
file, without any reader conditionals? The metadata will still be available to the macro.
Also, you're using clojure.string
without a corresponding :require
. If it's only because you didn't want to use the word clojure
in the ns
form of a .cljc
file, it's not an issue since the corresponding CLJS namespace is also clojure.string
.
Finally, the code is somewhat dangerous. If two type definitions are in the same ns and use that macro, they will create two different protocols with the same name. Probably will lead to issues, definitely a code smell.
Thanks for the tips. I understand where you're coming from with the code smell. I created a Github issue for myself to fix (lol).
> Why not just a .clj
file
Forgot to mention - for macros to be easily usable in CLJS files, there should also be a CLJS file with the same name that only has (:require-macros [%the-ns%])
in its ns
form, and nothing else (unless you need some CLJS-only functionality in that namespace). This will let users of the macro to use it by requiring the namespace in a regular way, without explicitly referring to macros.
I believe atomic-mutable is a chatgpt hallucination 😛
yes haha