[plt-scheme] easy way to see if something is defined?
On Wed, Mar 24, 2010 at 10:41 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> Is there a more efficient/idiomatic way to see if an identifier is
> currently defined other than
>
> (member blah (namespace-mapped-symbols (current-namespace)))
>
> ?
>
> Todd
That only works if the current namespace happens to correspond to the
code you are running. It often does not. At runtime, there is
probably no reliable way to find this out. At compile time, you can
use the "identifier-binding" procedure to find out about lexical and
module variables. Top-level variables (i.e. definitions outside
modules) aren't really "bound" in the same sense, and for them you
have to fall back on namespaces, which are at least set to something
predictable inside macro expanders.
--Carl