Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style warning in SBCL (unused variable) using DOPLIST #65

Open
filipencopav opened this issue Feb 17, 2022 · 2 comments
Open

Style warning in SBCL (unused variable) using DOPLIST #65

filipencopav opened this issue Feb 17, 2022 · 2 comments

Comments

@filipencopav
Copy link

Code to reproduce:

(defparameter *pandoc-vars*
  '(:mainfont "Liberation Sans"
     :documentclass "report"
     :geometry (:margin "2cm")))

(rtl:doplist (key val *pandoc-vars*)
  (princ (list val key)))

Warning:

; in: RUTILS.LIST:DOPLIST (KEY VAL *PANDOC-VARS*)
;     (DESTRUCTURING-BIND
;         (KPTB::KEY KPTB::VAL &REST #:G822)
;         #:G821
;       (PRINC (LIST KPTB::VAL KPTB::KEY)))
; ==>
;   (LET* ((#:G2
;           (SB-C::CHECK-DS-LIST/&REST #:G821 2 2
;                                      '(KPTB::KEY KPTB::VAL &REST #:G822)))
;          (KPTB::KEY (POP #:G2))
;          (KPTB::VAL (POP #:G2))
;          (#:G822 #:G2))
;     (PRINC (LIST KPTB::VAL KPTB::KEY)))
; 
; caught STYLE-WARNING:
;   The variable #:G822 is defined but never used.
; 
; compilation unit finished
;   caught 1 STYLE-WARNING condition
@filipencopav filipencopav changed the title Style warning in SBCL (unused variable) using DOPLIST (SBCL issue?) Style warning in SBCL (unused variable) using DOPLIST Feb 17, 2022
@filipencopav
Copy link
Author

Found that a variable for holding the rest of the list is created in destructuring-bind, but not used.
destructuring-bind works well in this scenario, i don't know if there's a way to tell it to discard the rest of the list. If there is, then it's possible to do that, otherwise, maybe use a simpler LET form?

(defmacro doplist ((key val plist &optional rez) &body body)
  "Like DOLIST but iterate over 2 items of the PLIST at once,
   onsidered KEY and VAL. Asserts proper PLIST."
  (once-only (plist)
    (with-gensyms (tail)
      `(progn
         (do ((,tail ,plist (cddr ,tail)))
             ((null ,tail) ,rez)
           (destructuring-bind (,key ,val &rest ,(gensym)) ,tail
;                                              ^
;                                              |
;                                             here
             ,@body))))))
(defmacro doplist ((key val plist &optional rez) &body body)
  "Like DOLIST but iterate over 2 items of the PLIST at once,
   onsidered KEY and VAL. Asserts proper PLIST."
  (rtl:once-only (plist)
    (rtl:with-gensyms (tail)
      `(progn
         (do ((,tail ,plist (cddr ,tail)))
             ((null ,tail) ,rez)
           (let ((,key (first ,tail))
                 (,val (second ,tail)))
             ,@body))))))

@jcguu95
Copy link

jcguu95 commented Apr 30, 2024

We only need to add (declare (ignorable ,rest)). A fix has been proposed in PR #72 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants