[pro] Defined but no used variable warning during setf expansion

Burton Samograd burton.samograd at gmail.com
Mon Jan 23 13:18:16 UTC 2012


Hello,

I am wondering if anyone can explain the reason for the defined
but not used variable in setf that this code is experiencing:

CL-USER> (set-macro-character  #\$
                     (lambda (stream char)
                       (declare (ignore char))
                       (let ((v (read stream)))
                         (list (get v 'setf-handler-name) v))))

(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)))

(defmacro setactive (var &key read-handler write-handler)
 `(progn
    (when ,read-handler
      (setf (get ',var :read-handler) ,read-handler))
    (when ,write-handler
      (setf (get ',var :write-handler) ,write-handler))))

(defactive x 0
 :write-handler (lambda (old-val new-val) (format t "old: ~A  new:
~A" old-val new-val))
 :read-handler (lambda (val) (format t "value: ~A" val) val))
;(setactive x :read-handler (lambda (val) (format t "~A !!! ~A" val)))
;(setactive x :write-handler (lambda (old-val new-val) (format t "~A
!!! ~A" old-val new-val)))

(defactive d6 (random 6)
 :read-handler (lambda (val) (let ((old val)) (setf d6 (random 6)) old)))

STYLE-WARNING: redefining COMMON-LISP-USER::DEFACTIVE in DEFMACRO
STYLE-WARNING: redefining COMMON-LISP-USER::SETACTIVE in DEFMACRO
1
CL-USER> (setf $x 10)
; in: SETF (#:G1129 X)
;     (LET* ((#:G1175 X))
;       (MULTIPLE-VALUE-BIND (#:G1176)
;           10
;         (LET ((#:G1177 #))
;           (WHEN #:G1177 (FUNCALL #:G1177 # #:G1176))
;           (SETF X #:G1176))))
;
; caught STYLE-WARNING:
;   The variable #:G1175 is defined but never used.
;
; compilation unit finished
;   caught 1 STYLE-WARNING condition
old: 0  new: 10
10

--
Burton Samograd
http://kruhft.dyndns.org




More information about the pro mailing list