This is probably a bit of a newbie question, but I'm trying to write a macro that detects whether an identifier is lexically bound at the point of macro expansion, and changes its output accordingly. Is this possible in R6RS Scheme, and if so, how?
Why I Want to Know
I'm writing a toy Objective-C binding layer in Chez Scheme, using macros, and my initial challenge is in dealing with Objective-C selectors efficiently. The program has to query the Objective-C runtime, at runtime, for the actual SEL
object corresponding to each selector name. The selector names used in the program will be known statically, during expansion, and it's easy enough to have my macros insert that query code, but I want to avoid repeat queries for the same selector name.
My first thought on this is to have some naming convention for Scheme definitions bound to SEL
foreign objects. That way, I could have one (define)
for each unique selector, and thus one runtime query per selector. This hinges on my macros being able to detect these bindings for any given selector, and introducing them if they do not already exist, hence my question.
This solution is still imperfect, since my macros may be expanded in inner scopes, but it was the most obvious to me. Is there a better way to "intern" expressions at expansion time?