emacs-devel
[Top][All Lists]
Advanced

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

RE: lengths and stuff


From: Tomas Hlavaty
Subject: RE: lengths and stuff
Date: Sun, 27 Dec 2020 18:56:08 +0100

On Sat 26 Dec 2020 at 21:23, Drew Adams <drew.adams@oracle.com> wrote:
> And as I said, `length' is not so special in this regard.  `map',
> `dolist', and others also provide the same rope to hang yourself with.

length is different than map and dolist.

length is about a property of a list, namely about number of items.

map and dolist are about doing something with items of list.

Using length in a predicate is yet completely different and most likely
bad because to answer the predicate, traversing the whole list is wasted
time and energy.

> There are no specific functions that can be used to avoid
> the trap.

There are not, but there could be.

> I see no help offered by `length<' & compagnie.

The idea is that the intent is expressed in a way that can _guarantee_
that useless length computation is avoided.

> And if the list in question is short, and the context is
> not performance-critical (e.g. tight loop that's important),
> then there may be no reason to bother about not traversing
> it entirely.  IOW, this stuff is best considered case by
> case.  Lisp already has all that's needed to create clear
> code that does what one wants AND conveys to human readers
> what's done and why.

In theory.  In reality, look at emacs code.  The new predicates will
allow not worrying about the trap and be sure that it is not there.  And
if somebody falls in the trap again, the new predicates will make it
easy to fix, simply by search and replace.

> If a given case has no performance impact, then it's
> maybe better NOT to provide code that might give the
> impression that we're trying to avoid a particular
> performance penalty.  Of course in middle cases, which
> might not be obvious to a human reader, we may need to
> make things clear explicitly.

But how do you know if it has or has not performance impact unless you
investigate each case?

With the new predicates, you do not need to investigate each case
because it will be taken care automatically.

> I wouldn't be in favor of systematically avoiding use
> of `length', as if all uses are poisonous.

In fact, it kind of is, especially when used in a predicate.

> That would almost be akin to wrapping all uses of `dolist' in a
> `catch'.

Why?  That does not make sense.



reply via email to

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