emacs-devel
[Top][All Lists]
Advanced

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

Re: Replace trivial pcase occurrences in the Emacs sources


From: Clément Pit-Claudel
Subject: Re: Replace trivial pcase occurrences in the Emacs sources
Date: Wed, 24 Oct 2018 15:00:46 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

On 24/10/2018 12.00, Eli Zaretskii wrote:
>> From: Clément Pit-Claudel <address@hidden>
>> The repetition of "eq" in each "cond" branch just looks redundant to me
> 
> If that's what bugs you, then how about
> 
>   (setq foo (assoc bar '((1 . one) (2 . two) ...)))

This only works for constant branch bodies, and I find it marginally harder to 
read (especially if a default value is specified).
But I agree that it's not a bad solution when the branch body is constant.
For large collections, I imagine you would use a hashtable? Is that how the 
switch bytecode is implemented? IIUC, cond and pcase will be translated to a 
switch, but not assoc, even with a constant association list.

>> and I have no trouble reading the pcase forms.
> 
> Please don't forget those who will read your code.  A code is written
> once, but read many times.  It should be readable and
> self-explanatory.

Of course. Note that I mentioned reading the pcase forms, not writing them. I'm 
just pointing out that there are readers who find pcase more readable than 
either assoc or cond with eq tests.



reply via email to

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