[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lengths and stuff
From: |
Eric Abrahamsen |
Subject: |
Re: lengths and stuff |
Date: |
Mon, 28 Dec 2020 08:44:19 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Jean Louis <bugs@gnu.support> writes:
> * Tomas Hlavaty <tom@logand.com> [2020-12-27 23:53]:
>> On Sun 27 Dec 2020 at 10:52, Drew Adams <drew.adams@oracle.com> wrote:
>> >> 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.
>> >
>> > (lambda (xs) (= (length xs) 25)) ; need to count elts
>>
>> Is that a joke?
>>
>> The predicates were proposed to help programers avoid writing such bad
>> code. And if somebody writes such bad code, it is almost trivial to fix
>> it with search and replace:
>>
>> "(= (length" -> "(length="
>> "(< (length" -> "(length<"
>> "(> (length" -> "(length>"
>> "(/= (length" -> "(length/="
>> "(<= (length" -> "(length<="
>> "(>= (length" -> "(length>="
>>
>> Also the "symmetry" (or exhaustiveness?) here is to assist in easily
>> fixing bad code with minimum changes.
>>
>> Nothing of course helps to those who are determined to unneccessarily
>> count _all_ the elements of lists.
>
> May I understand if that proposal is to implement it in C or in Lisp?
> Does that mean when (length< list-1 10) is implemented in C it would
> become faster than: (< (length list-1) 10) ?
>
> Or is that proposal to make Lisp functions like:
>
> (defun length< (list n)
> (when (< (length list) n)
> t))
They're already implemented in Emacs master, and they're in C. As I
understand it, one of the main advantages (beyond being simply faster,
possibly) is that they return early: if all you want to do is check if a
list has more than 2 elements, you don't have to calculate the whole
length, you can return t once you've found the third element.
- Re: Internationalize Emacs's messages (swahili), (continued)
- Re: Internationalize Emacs's messages (swahili), Alfred M. Szmidt, 2020/12/27
- Re: Internationalize Emacs's messages (swahili), Jean Louis, 2020/12/28
- Re: Internationalize Emacs's messages (swahili), Eli Zaretskii, 2020/12/26
- RE: Internationalize Emacs's messages (swahili), Drew Adams, 2020/12/26
- lengths and stuff, Daniel Brooks, 2020/12/26
- RE: lengths and stuff, Drew Adams, 2020/12/27
- RE: lengths and stuff, Tomas Hlavaty, 2020/12/27
- RE: lengths and stuff, Drew Adams, 2020/12/27
- RE: lengths and stuff, Tomas Hlavaty, 2020/12/27
- Re: lengths and stuff, Jean Louis, 2020/12/28
- Re: lengths and stuff,
Eric Abrahamsen <=
- Re: Internationalize Emacs's messages (swahili), Eli Zaretskii, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Richard Stallman, 2020/12/27
- Re: Internationalize Emacs's messages (swahili), Eli Zaretskii, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Daniel Brooks, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Eli Zaretskii, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Daniel Brooks, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Eli Zaretskii, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Daniel Brooks, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Werner LEMBERG, 2020/12/26
- Re: Internationalize Emacs's messages (swahili), Daniel Brooks, 2020/12/26