[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get plist properties list?
From: |
Jean Louis |
Subject: |
Re: How to get plist properties list? |
Date: |
Fri, 8 Jan 2021 08:46:44 +0300 |
User-agent: |
Mutt/2.0 (3d08634) (2020-11-07) |
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-01-08 08:23]:
> > (dotimes (i length (reverse properties))
> > (if (divisible-by-2-or-0-p i)
> > (push (elt plist i) properties)))))
>
> This is another example of a dotimes+elt loop, i.e. a loop where you
> end up with an unwarranted O(n²) complexity (i.e. a performance bug).
Yes, I know there are complexities, but it did not bother me really.
Only compiler warnings bother me.
> > (while (/= n (length plist))
> > (push (elt plist n) properties)
> > (setq n (+ 2 n)))
> > properties))
>
> Same problem here.
I would like to understand what is the problem. I don't. You tell me
that `elt' is problem, that is how I understand it.
Could I maybe rather use `nth' to replace `elt'?
(elt '(1 2 3) 0)
(nth 0 '(1 2 3))
Which one is faster?
> > But maybe there is some more simpler way to get plist properties list?
>
> Probably not the simplest but this should work:
>
> (defun plist-keys (plist)
> (let (keys iskey)
> (dolist (x plist)
> (if (setq iskey (not iskey)) (push x keys)))
> (nreverse keys)))
As we already discussed it, `dolist' is not perfect, it would give
warnings, not logical at all. In the above example `x' would not give
warning, but if there would be return value then `x' would be part of
warning, while return variable would not be. That is not logical to
me, so I consider `dolist' not well handled by compiler and is better
for me not to use it.
> The simplest might be:
>
> (map-keys plist)
That is it. Why not start with that one...
Jean
- 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/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, 2021/01/11
- 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 <=
- 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
- Re: How to get plist properties list?, Jean Louis, 2021/01/10
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/09
- Re: How to get plist properties list?, Jean Louis, 2021/01/12
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/12
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Jean Louis, 2021/01/07
Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Stefan Monnier, 2021/01/07