Common Lisp: check if lexical variable exists?
<p>How do I detect if a lexical variable is bound in a scope? I basically want <code>boundp</code> for lexical variables.</p>

<p>Concretely, say I have:</p>

<pre><code>(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.")))
</code></pre>

<p>So <code>boundp</code> correctly checks for dynamic variables (and constants), and <a href="http://clhs.lisp.se/Body/f_boundp.htm" rel="noreferrer">as the hyperspec says</a>, doesn't cover lexical bindings. </p>

<p>But I can't find any equivalent of <code>boundp</code> for lexical bindings. So how do I check them then? (Implementation-specific code for say SBCL is fine if there isn't anything portable.)</p>