Subject: Re: Does a variable exist? NEWBIE NEWBIE NEW
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1999/10/29
Newsgroups: comp.lang.scheme
Message-ID: <7vb8cq$1efvs@fido.engr.sgi.com>
Lou Langevin  <llangevi@us.ibm.com> wrote:
+---------------
| I want to check for the existence of a variable...
+---------------

The bad news is that the Scheme standard *DOESN'T* define a way to do this.

The good news is that most popular implementations *DO* provide this
functionality, but because it's not in the standard, the syntax and
semantics vary from implementation to implementation.  (*sigh*)
Here are a few variations:

MzScheme: (defined? 'foo) "defined?" is a function, takes a symbol as an arg
			  thus can be used inside other functions which are
			  passed symbols as args. True if symbol has a global
			  definition (but never true of lexically-bound vars).

SCM:      (defined? foo)  That is, "defined?" is a *macro*, and takes an
			  *unquoted* symbol, and thus mostly useful only
			  at the top level. Like MzScheme's, never true of
			  lexically-bound vars.

Elk:      (bound? 'foo)   "bound?" is a function, takes a symbol as an arg,
			  but is is true if the symbol has *either* a top-level
			  or lexical binding.

+---------------
| I came across the [symbol?] command and was wondering if this was
| it's purpose.
+---------------

No, "symbol?" is just one of a number of "type predicate" (others include
"boolean?", "number?", "vector?", etc.) The "symbol?" predicate may be
safely applied to *any* Scheme object, but is only true if that object
is in fact a symbol. E.g.:

	> (define foo 123)
	> foo
	123
	> (symbol? foo)
	#f
	> (symbol? 'foo)
	#t
	> (map symbol? (map string->symbol '("abc" "def")))
	(#t #t)
	> 


-Rob

-----
Rob Warnock, 8L-846		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA