help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to avoid compiler warning `unused lexical variable' for `dolist'


From: Jean Louis
Subject: Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?
Date: Thu, 7 Jan 2021 14:00:56 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> [2021-01-07 13:07]:
> Jean Louis wrote:
> 
> > (defun db/table-id-plist (table id pg)
> >   "Returns plist for table by its table_id"
> >   (let* ((columns (db/table-columns table pg))
> >      (sql (db/sql-by-columns table columns id))
> >      (values (rcd-sql-first sql pg))
> >      (values (append values nil))
> >      (length (length columns))
> >      (plist '()))
> >     (dotimes (i length plist)
> >       (setf plist (plist-put plist (intern (elt columns i)) (elt values 
> > i))))))
> >
> > What is proper way to avoid this warning in `dolist' or
> > `dotimes':
> >
> > rcd-db.el:841:1: Warning: Unused lexical variable ā€˜iā€™
> >
> > Declaring variable `i' in `let' before `dolist' or `dotimes'
> > did not help.
> 
> Right. Let's just say it is a `dotimes' thing, see line
> 309-310, /usr/local/share/emacs/28.0.50/lisp/subr.el
> 
>   ;; FIXME: This let often leads to "unused var" warnings.
>   `((let ((,(car spec) ,counter)) ,@(cddr spec))))))
> 
> (require 'cl-lib)
> 
> (defun db/table-id-plist (table id pg)
>   "Do something with TABLE, ID and PG."
>   (let*((cols   (db/table-columns table pg))
>         (sql    (db/sql-by-columns table cols id))
>         (vals   (rcd-sql-first sql pg))
>         (plist) )
>     (cl-loop for c in cols
>              for v in vals
>              do (setf plist (plist-put plist (intern c) v)) )))

Thank you.

cl-loop I have used all times in Common Lisp, fine, but not so
nice. So instead of `dolist' I can use mapcar or similar function with
lambda and there is no complaint.

I would rather like to solve `dolist' compiler complain, and not
change to more complex `cl-loop' and avoid changing to `mapcar' usage.

Jean



reply via email to

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