I'm trying to create a macro or something that will run a body with all the keys in a hashtable passed to it bound to their values in a local environment. I.e if I have a hashtable *foo* which has the key 'a bound to 1 and 'b bound to 2, I would want something like this:
(let ((a 1)
(b 1))
body)
My first attempt was this:(defmacro with-unpacked-table (hashtable &body body)
`(let ,(loop for key being the hash-keys of (eval hashtable)
using (hash-value value)
collecting `(,key ,value))
,@body))
This obviously doesn't work because the hashtable has to be present at macro expansion time. This goes for most similar solution. The options are ugly. I could define a package and defparameter all of them inside it, etc, but that's sort of stupid. The only thing I could think of was the scheme eval where you can pass it an environment. Then I could easily write a function to convert from a hash table to whatever format the environment needs to have, and do something like this:(defmacro with-unpacked-table (hashtable &body body)
`(eval (progn ,@body)
(hash-to-env ,hashtable)))
Is there any equivalent technique in Common Lisp?