I’m creating a cljc function that needs to dispatch based on whether one of its args is an atom. This SO answer suggests: (defn atom? (instance? clojure.lang.IAtom x))
The answer is old and that answer wouldn’t work in cljs, anyway. Is there a simple way to get both? preferably without reader conditionals?
It will give you false positives for lots of things: refs, futures, delays… Also may block for a long time if it’s a promise. I personally see no problems with using reader conditionals:
Thanks all! Trying the solution @vlaad gave, I realized I’d forgotten an important corollary: I was in CLJC but I needed to also get “true” on reformation.core/atom. In this case, the duck-typing I put earlier worked ok (since I couldn’t find any common ground between reagent atoms and other atoms). This is part of a library in a fairly constrained domain, so I’m not too worried about non-atom de-reffables (actually, I probably don’t know many of those).
When I hit the same problem, I eventually figured out that I don’t really need to know if something is an atom, but whether it is derefable. So I use this: