Fork me on GitHub
#clojurescript
<
2024-02-03
>
Janet A. Carr15:02:41

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?

Janet A. Carr15:02:01

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?

p-himik15:02:26

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

Janet A. Carr15:02:53

This is what I thought. :thinking_face:

Janet A. Carr15:02:17

Will post code, give me a second.

p-himik16:02:13

Why not just a .clj file, without any reader conditionals? The metadata will still be available to the macro.

p-himik16:02:42

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.

p-himik16:02:22

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.

Janet A. Carr16:02:23

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

p-himik16:02:20

Also, what's :atomic-mutable?

p-himik16:02:28

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

👍 1
Janet A. Carr17:02:36

I believe atomic-mutable is a chatgpt hallucination 😛

p-himik17:02:59

Ah. :mutable is also not a thing in CLJ, it only exists in CLJS.