How can I check a variable is defined before or not within the let construct?
(let (((if (boundp 'a)
'a
'dummy) t))
(message "I made this work"))
What I am trying to do is to check whether or not a is bounded before, if it is already, bind it to t locally. otherwise don’t care about a at all.
The code fails with:
(wrong-type-argument symbolp (if (boundp (quote a)) (quote a) (quote dummy))), indicating that theletspecial form* does not evaluate that argument (although that list would evaluate to a symbol, the list itself is not a symbol).Here’s a simple-but-flawed alternative approach which creates a local binding for
aregardless, but then unbinds it in that local scope if it was unbound originally.The flaw is that if
awas initially unbound, you would want an assignment toawithin that local scope to outlive the local scope, and it won’t with this approach.Initially I was thinking you’d need to forego
letentirely to get around that issue, and just use something like this:Then I realised that, as with so many things, macros are the answer: