|
From: | Stefan Monnier |
Subject: | Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'? |
Date: | Sat, 09 Jan 2021 14:01:54 -0500 |
User-agent: | Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
>> (let ((i --dotimes-counter--)) plist)) > > In Common Lisp, that part would be solved by (declare (ignorable i)) in > the macro: > > (let ((i --dotimes-counter--)) > (declare (ignorable i)) > plist) > > I do not know if Emacs Lisp has ignorable. We have something equivalent: (let ((i --dotimes-counter--)) (ignore i) plist) [ Which "comes for free" in the sense that it is not the result of deliberate design but rather the simple fact that the `ignore` function is usually optimized away (but it's optimized late enough that the `i` passed to it still counts as a use of that variable). ] >> You won't get this warning if you do: >> >> (dotimes (i length (progn (ignore i) plist)) >> (setf plist (plist-put plist (intern (elt columns i)) (elt values i)))) >> or >> (dotimes (i length) >> (setf plist (plist-put plist (intern (elt columns i)) (elt values i)))) >> plist > > This is just moving the problem from macro author to macro users. Indeed, and it reflects the fact that some of those who get to decide (e.g. yours truly) don't like this 3rd arg. Stefan
[Prev in Thread] | Current Thread | [Next in Thread] |