Re: How to tell if a variable is bound

2009-02-12 Thread Chouser
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

Re: How to tell if a variable is bound

2009-02-12 Thread James Reeves
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_,

Re: How to tell if a variable is bound

2009-02-12 Thread Laurent PETIT
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

Re: How to tell if a variable is bound

2009-02-12 Thread Jeffrey Straszheim
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

How to tell if a variable is bound

2009-02-12 Thread Conrad
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