vseloved / rutils

Radical Utilities for Common Lisp
Other
250 stars 37 forks source link

dotable compilation breaks if body contains (declare (ignore ...)) #57

Closed mirkov closed 4 years ago

mirkov commented 4 years ago

The issue is really not a show-stopper. I am raising it as fixing it eliminates an unexpected error that may throw off a user. Also, dolist accepts declare forms. So should then dotable

The following code (adapted from the tutorial):

(let ((rez ()))
  (dotable (k v #h(1 :foo 2 :bar) rez)
    (declare (ignore v))
    (when (oddp k)
      (push k rez))))

does not compile because in the macro-expansion a NIL is inserted by the ,(when '(declare (ignore )) form. When _ is nil, when returns nil and the declaration is placed incorrectly:

                (DOLIST (#:G11537 #:TABLE11538)
                  (DESTRUCTURING-BIND
                    (K . V)
                    #:G11537
                    NIL ; generated by the when form
                    (DECLARE (IGNORE V))
                    (WHEN (ODDP K) (PUSH K REZ))))

To avoid generating the NIL, the when form needs to be written like so:

,@(when _ `((declare (ignore _)))

Note the @ and the extra parenthesis around declare.

This whole problem can and should be avoided by using the _ underscore, eliminating the need for the user to use declare.

Again, I raise this, as it raises an error whereas dolist would not issue one.

vseloved commented 4 years ago

well, it is expected that you use _ for ignored variables instead of an explicit declaration :) But I've updated the code to handle your case as well