On Mon, Jan 23, 2012 at 5:18 AM, Burton Samograd burton.samograd@gmail.com wrote:
Hello,
I am wondering if anyone can explain the reason for the defined but not used variable in setf that this code is experiencing:
I don't know for sure, but there are a couple of things that are odd about your macro-writing macro. One is that in the `defmacro' and `defsetf' it generates, the `var' passed in the outer macro call is reused as a parameter of the generated macro and setf expander. The other is the two calls to `eval'.
I haven't taken the time to work out why those things are there, but I would suggest they probably shouldn't be. Try getting rid of them and see what happens.
-- Scott
(defmacro defactive (var value &key write-handler read-handler) (let ((setf-handler-name (gensym))) `(progn (defparameter ,var ,value) (defmacro ,setf-handler-name (,var) (let ((read-handler (gensym))) `(let ((,read-handler (get ',',var :read-handler))) (if ,read-handler (funcall ,read-handler (eval ,',var)) ,',var)))) (defsetf ,setf-handler-name (,var) (new-val) (let ((write-handler (gensym))) `(let ((,write-handler (get ',',var :write-handler))) (when ,write-handler (funcall ,write-handler (eval ,',var) ,new-val)) (setf ,',var ,new-val)))) (setf (get ',var 'setf-handler-name) ',setf-handler-name) (setf (get ',var :write-handler) ,write-handler) (setf (get ',var :read-handler) ,read-handler) ,value)))