How do I detect if a lexical variable is bound in a scope? I basically want boundp
for lexical variables.
Concretely, say I have:
(defvar *dynamic* 1)
(defconstant +constant+ 2)
(let ((lexical 3))
(when (boundp '*dynamic*) ; t
(print "*dynamic* bound."))
(when (boundp '+constant+) ; t
(print "+constant+ bound."))
(when (boundp 'lexical) ; nil
(print "lexical bound.")))
So boundp
correctly checks for dynamic variables (and constants), and as the hyperspec says, doesn't cover lexical bindings.
But I can't find any equivalent of boundp
for lexical bindings. So how do I check them then? (Implementation-specific code for say SBCL is fine if there isn't anything portable.)
boundp
works for lexical bindings in Emacs Lisp, so I already have some Emacs Lisp code that works that way, and would like to port it in the most simple and straightforward way. – Afterbodylexical-binding
is in effect for a given file,boundp
works like in Common Lisp here. It just so rarely is in effect in my code, I didn't even notice. :)) – Afterbody