emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: false warnings when compiling with lexical-binding and cl-lib.


From: Thierry Volpiatto
Subject: Re: false warnings when compiling with lexical-binding and cl-lib.
Date: Sat, 23 Nov 2013 07:13:12 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> here a sample file containing a function using loop:
>
>> --8<---------------cut here---------------start------------->8---
>> ;;; test.el --- test loop -*- lexical-binding: t -*-
>
>> (require 'cl-lib)
>
>> (defun test-with (l)
>>   (cl-loop with lst
>>            for i in l
>>            unless (member i lst)
>>            collect i into lst
>>            finally return lst))
>> --8<---------------cut here---------------end--------------->8---
>
>> When compiling this file I have a warning about unused arg `lst'.
>> Is this wanted ?
>
> No, it's not wanted.  But noone so far as been able to come up with
> a patch to fix it (the code to fix is the cl-loop macro: look at the
> macro-expanded code to see the unused `lst').

This patch avoid adding a new binding by the 'into' clause when the
binding have been already added by a 'with' clause.
I wonder if this is correct, real common-lisp return an error in such
case, WDYT?

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 2209297..63cf7a1 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -1564,9 +1564,11 @@ If BODY is `setq', then use SPECS for assignments rather 
than for bindings."
 
 (defun cl--loop-handle-accum (def &optional func) ; uses loop-*
   (if (eq (car cl--loop-args) 'into)
-      (let ((var (cl--pop2 cl--loop-args)))
+      (let* ((var (cl--pop2 cl--loop-args))
+             (binding (list (list var def))))
        (or (memq var cl--loop-accum-vars)
-           (progn (push (list (list var def)) cl--loop-bindings)
+            (member binding cl--loop-bindings)
+           (progn (push binding cl--loop-bindings)
                   (push var cl--loop-accum-vars)))
        var)
     (or cl--loop-accum-var
--8<---------------cut here---------------end--------------->8---

-- 
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]