Subject: Re: procedure-defined?
From: (Rob Warnock)
Date: 2000/05/02
Newsgroups: comp.lang.scheme
Message-ID: <8elmnj$652ho$>
Colin Walters  <> wrote:
| "John" == John Clonts <> writes:
| John> How can you determine if a procedure is defined?
| I don't believe you can in straight R5RS.  However, guile has procedure?.

All R[45]RS Schemes have "procedure?", but that's not the issue. That is,
he asked the wrong question, which should be: "How do you determine if a
variable (as represented by a symbol) has a global binding?", and indeed,
*that* question can't be answered in R[45]RS Scheme. (Once you know that
the variable is bound to some value, then you can safely ask "procedure?"
of that value...)

However, various Scheme implementations have their own proprietary versions
of that: "bound?", "defined?", etc. For example, in MzScheme:

	> (define (type-of-global-symbol x)
	    (if (symbol? x)
	      (if (defined? x)
	        (let ((v (global-defined-value x)))
		    ((procedure? v) 'procedure)
		    ((symbol? v) 'symbol)
		    ((number? v) 'number)
		    ((pair? v) 'pair)
		    ((vector? v) 'vector)
		    ((string? v) 'string)
		    ((boolean? v) 'boolean)
		    (else 'unknown-type)))
	      (error "Not a symbol:" x)))
	> (type-of-global-symbol 'foo)
	> (type-of-global-symbol 'car)
	> (type-of-global-symbol 123)
	Not a symbol: 123
	> (define bar 456)
	> (type-of-global-symbol 'bar)

[Note that in SCM (and thus in Guile?), "defined?" is *syntax*,
not a procedure, and thus cannot be used in the manner shown above...]


Rob Warnock, 41L-955
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043