[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to avoid compiler warning `unused lexical variable' for `dolist'
From: |
Leo Butler |
Subject: |
Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'? |
Date: |
Mon, 11 Jan 2021 06:53:13 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> ********************************************************
> Caution: This message was sent from outside the University of Manitoba.
> ********************************************************
>
>>> This distinction becomes relevant if BODY modifies VAR or captures it
>>> in a closure.
>> Maybe I am being thick, but I cannot think of how there would be a
>> different behaviour.
>
> Try:
>
> (let (funs)
> (dotimes (i 5)
> (push (lambda () i) funs))
> (mapcar #'funcall funs))
>
> IIUC the version you advocate would return
>
> (5 5 5 5 5)
>
> whereas the current version returns
>
> (4 3 2 1 0)
Thanks, I was being thick.
----
I realize that elisp does not claim to be a dialect of common lisp, but
it would be helpful to note that this behaviour deviates from the
behaviour of several CL implementations (gcl, clisp, sbcl, ecl).
The CL standard (http://clhs.lisp.se/Body/m_dotime.htm) says:
....
It is implementation-dependent whether dotimes establishes a new
binding of var on each iteration or whether it establishes a binding
for var once at the beginning and then assigns it on any subsequent
iterations.
>
> Other differences occur if you do
>
> (let (vals)
> (dotimes (i 10)
> (push (setq i (1+ i)) vals))
> vals)
Yes.
Leo
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, (continued)
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Philipp Stephani, 2021/01/08
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Emanuel Berg, 2021/01/08
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, tomas, 2021/01/08
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Jean Louis, 2021/01/09
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Leo Butler, 2021/01/09
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Philipp Stephani, 2021/01/09
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Leo Butler, 2021/01/09
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Stefan Monnier, 2021/01/09
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?,
Leo Butler <=
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Stefan Monnier, 2021/01/11
- RE: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Drew Adams, 2021/01/07
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Stefan Monnier, 2021/01/07
- RE: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Drew Adams, 2021/01/08
- How to get plist properties list?, Jean Louis, 2021/01/07
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/08
- Re: How to get plist properties list?, Jean Louis, 2021/01/08
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/08
- Re: How to get plist properties list?, Jean Louis, 2021/01/09
- Re: How to get plist properties list?, tomas, 2021/01/09