| So, I am in the process of writing a macro, w/tab, that binds the keys of a hash table to their values. If we have a hash table, z, that looks like hash#((a . 1) (b . 2))
then w/tab will bind the variable a to 1, and b to 2. w/tab also takes a body, and executes the body in the scope of these variable bindings. So far I have this (mac w/tab (ht . body)
(w/uniq bindings
`(let ,bindings (flat (tablist ,ht))
(eval `(with ,,bindings
,@',body)))))
This works, although it would be nice to not have to do the (eval).The next step is to update the hash table with any values that were changed in the body. Example, (w/tab z
(= a 4))
After execution of this form, z should look like #hash((a . 4) (b . 2)). Here is my attempt at doing the updating, (mac w/tab (ht . body)
(w/uniq (bindings k)
`(let ,bindings (flat (tablist ,ht))
(eval `(with ,,bindings
(= res (do ,@',body))
(each ,',k (keys ,',ht)
(= (,',ht ,',k) (eval ,',k)))
res)))))
I set the result of executing body to res, then loop through the keys of the hash table, trying to reassign their new values. The problem is that the (eval) call in the (each) loop throws an error. Apparently the expansion of (with) doesn't allow eval'ing the symbols of its bindings.I'm stuck at this point, and would appreciate any advice on what I might do to write something that supports this behavior. - mpr |