Fork me on GitHub
#clojurescript
<
2022-03-25
>
shaun-mahood19:03:08

https://twitter.com/MitjaBezensek/status/1507428796223401985?s=20&amp;t=PcAofLxjgU3aQslNzbJnsw We have a lot of code at Pitch, but it’s still pretty easy to get around and fun to work with. Anyone else have large CLJS projects that they still like working with?

😎 4
metal 2
isak19:03:30

89431 for us, still feels good

πŸ‘ 2
metal 2
ribelo19:03:30

πŸŽ‰ 1
Carlo20:03:06

In Clojure, if I want to check if a function supports metadata, I can check (instance? clojure.lang.IObj value). What is the corresponding test in Clojurescript?

p-himik20:03:53

(defprotocol IMeta
  "Protocol for accessing the metadata of an object."
  (^clj-or-nil -meta [o]
    "Returns the metadata of object o."))

(defprotocol IWithMeta
  "Protocol for adding metadata to an object."
  (^clj -with-meta [o meta]
    "Returns a new object with value of o and metadata meta added to it."))

❀️ 1
Carlo20:03:28

Thank you @U2FRKM4TW! How did you find the relative code? Grepping the cljs source? So my check would be (instance? #?(:clj clojure.lang.IObj :cljs IWithMeta) value), right?

p-himik20:03:38

Just opened core.cljs in my IDE and looked through all the symbols containing the word meta. The check seems reasonable to me, although not sure why you have an FQN there for IObj but not for IWithMeta.

Carlo20:03:16

I didn't test the cljs part yet (it's my first cljc experiment, and I'm not used to open it in both repls), so the cljs side could very well be wrong!

Carlo20:03:49

I guess I should add a shadow-cljs config and open the other one too!

djblue21:03:22

I use:

(defn can-meta? [value]
  #?(:clj  (instance? clojure.lang.IObj value)
     :cljs (implements? IWithMeta value)))

πŸ™Œ 1
p-himik21:03:34

Ah, right - the predicates should be different, thanks for correcting.

Carlo22:03:54

thank you, that's a very useful function!