Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether a symbol is bound

Tags:

guile

In Emacs Lisp (boundp 'symbol) returns t if symbol is bound to some value, nil otherwise. Is there an equivalent procedure in Guile Scheme?

like image 838
Ernest A Avatar asked Dec 08 '25 10:12

Ernest A


1 Answers

Scheme avoids leaking implementation into the specification and speaks of 'identifiers' rather than of binding an interned symbol to a value - see §2.1 of R7RS. In scheme, an 'identifier' is just a name.

An identifier name is treated as identifying a variable unless it identifies a macro (syntax) or it is in a context requiring it to be treated as identifying a symbol, such as by quotation. In particular, §2.1 of R7RS states that "When an identifier appears as a literal or within a literal (see section 4.1.2), it is being used to denote a symbol (see section 6.5)". You can test whether an identifer identifies a symbol with the symbol? procedure.

Guile scheme does in fact implement identifiers by interning symbols and you can query whether a symbol is bound using defined?:

(defined? 'num)

=> #f

(define num 1)(defined? 'num)

=> #t

This is a guile implementation matter and not portable scheme.

Edit: Note that defined? only works with top level variables defined with define. It does not work with let and cognates.

like image 178
Chris Vine Avatar answered Dec 11 '25 09:12

Chris Vine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!