On Thu, Feb 12, 2009 at 7:10 PM, Conrad wrote:
>
> Hi, is there a standard way to tell if a variable is bound? I couldn't
> find a way.
> Basically I want something like this, but without the horrible hacks:
>
>> (def foo 33)
That's actually doing two different steps:
1. creating a Var named 'fo
On Feb 13, 12:10 am, Conrad wrote:
> Hi, is there a standard way to tell if a variable is bound? I couldn't
> find a way.
There's an isBound method on the Var class:
(.isBound #'foo)
But the var has still got to exist, i.e. you have to (declare foo)
first.
If you want to check a var _exists_,
There's certainly better, but at least, you can try this :
(def void)
(.isBound (var void))
; or (.hasRoot (var void)) depending on what you want
--
Laurent
2009/2/13 Conrad
>
> Hi, is there a standard way to tell if a variable is bound? I couldn't
> find a way.
> Basically I want something
Try:
(contains? (ns-map *ns*) 'foo)
*ns* binds to the current namespace.
On Thu, Feb 12, 2009 at 7:10 PM, Conrad wrote:
>
> Hi, is there a standard way to tell if a variable is bound? I couldn't
> find a way.
> Basically I want something like this, but without the horrible hacks:
>
> (defn bou
Hi, is there a standard way to tell if a variable is bound? I couldn't
find a way.
Basically I want something like this, but without the horrible hacks:
(defn bound? [var]
(try (eval var)
true
(catch java.lang.Exception x false)))
> (bound? 'foo)
false
> (def foo 33)
33