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

[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: Sat, 9 Jan 2021 10:54:17 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* Stefan Monnier <monnier@iro.umontreal.ca> [2021-01-08 09:51]:
> > 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'?
> 
> No, same problem.
> Think of it this way: consider your list of N elements as a road that's
> N kilometers long.  `elt` and `nth` are operations which involve walking
> from the beginning of the road to the Nth kilometer.  So to collect all
> the keys found at kilometers 0, 2, 4, ... your loop does:
> - walk 0 kilometers and collect the key (then come back).
> - walk 2 kilometers from the start and collect the key (then come back).
> - walk 4 kilometers from the start and collect the key (then come back).
> - walk 6 kilometers from the start and collect the key (then come
> back).

So far I have seen from similar discussion on `length' on emacs-devel
mailing list, people were discussing of its efficiencies and maybe now
you also discuss of efficiency. For me as programmer of systems that I
need I use `elt' about 200+ times in all programs. `nth' I use less
times, maybe 30 times. I do not know what is a big difference between
those two.

If I wish to get the element like number 17th I do not know what I
should do. And I did not read all emails. I also do not feel why it
should be wrong, finally it is not really kilometers but computer
doing its iteration over elements. The above statement is unclear to
me as your distant student. I do understand you speak of efficiency,
but practically I yet do not see the problem. For example I cannot
practically at this moment find some delays that would bother me. 

> >> > 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.
> 
> There's no warning for this code, AFAIK, no.
> 
> > 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.
> 
> Just never use that 3rd argument and you'll never get that warning.

I do understand your point, but I also remember that warning was not
about the third argument and that when macro is defined as such then
programmers shall use it.

In my opinion compiler should not warn when programmer uses function
by its description. But when you make something obsolete, then I would
say it would be fine. `dolist' seem like Common Lisp so I was
expecting it to work as CL.

I will see more emails after this one.

Jean



reply via email to

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