[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.
- Re: Replace trivial pcase occurrences in the Emacs sources, (continued)
- Re: Replace trivial pcase occurrences in the Emacs sources, Eli Zaretskii, 2018/10/30
- Re: Replace trivial pcase occurrences in the Emacs sources, Michael Heerdegen, 2018/10/30
- Re: Replace trivial pcase occurrences in the Emacs sources, Eli Zaretskii, 2018/10/30
- Re: Replace trivial pcase occurrences in the Emacs sources, Michael Heerdegen, 2018/10/30
- Re: Replace trivial pcase occurrences in the Emacs sources, Eli Zaretskii, 2018/10/31
- Re: Replace trivial pcase occurrences in the Emacs sources, Clément Pit-Claudel, 2018/10/24
- Re: Replace trivial pcase occurrences in the Emacs sources, Eli Zaretskii, 2018/10/24
- Re: Replace trivial pcase occurrences in the Emacs sources,
Clément Pit-Claudel <=
- Re: Replace trivial pcase occurrences in the Emacs sources, Eli Zaretskii, 2018/10/24
- Re: Replace trivial pcase occurrences in the Emacs sources, Alan Mackenzie, 2018/10/24
- Re: Replace trivial pcase occurrences in the Emacs sources, Stefan Monnier, 2018/10/24
- Re: Replace trivial pcase occurrences in the Emacs sources, Stephen Berman, 2018/10/25
- Re: Replace trivial pcase occurrences in the Emacs sources, Eli Zaretskii, 2018/10/25
- Re: Replace trivial pcase occurrences in the Emacs sources, Stefan Monnier, 2018/10/25
- Re: Replace trivial pcase occurrences in the Emacs sources, Stefan Monnier, 2018/10/26
- Re: Replace trivial pcase occurrences in the Emacs sources, Garreau\, Alexandre, 2018/10/27
- Re: Replace trivial pcase occurrences in the Emacs sources, Richard Stallman, 2018/10/24
- Re: Replace trivial pcase occurrences in the Emacs sources, Joost Kremers, 2018/10/24