Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

In clojure.core there is a bound? function.

I can't see this function or something similar in cljs.core.

Why is that? Is there a replacement?

1 Answer

+1 vote
by
selected by
 
Best answer

Most likely because ClojureScript has no Var. def uses JS variables directly, and so there is no Var as in Clojure, that means no root value, no thread local, and no unbound Vars, meaning we don't need the bound? fn.

Ergo, In ClojureScript you can assume that your defs are always bounded defaulting to nil if you didn't specify a value.

So in a way, though it's not exactly the same, you can use some? instead.

In ClojureScript:

(def a)
(some? @#'a)
=> false

Note that some? checks the value, so you need to deref or just use the value directly like:

(some? a)
=> false

In Clojure:

(def a)
(bound? #'a)
=> false

Keep in mind though that:

(def a nil)
(some? a)
=> false

And

(def a nil)
(bound? #'a)
=> true

That's why it is not exactly the same.

...