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: Garreau\, Alexandre
Subject: Re: Replace trivial pcase occurrences in the Emacs sources
Date: Wed, 24 Oct 2018 20:47:39 +0200
User-agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-09-15, modified by Debian

On 2018-10-24 at 17:30, Michael Heerdegen wrote:
> Eli Zaretskii <address@hidden> writes:
>
>> FWIW, my main problem is not even with cl-case, it's with 'cond'.  It
>> seems like we have some 'pcase' epidemic, whose first symptom is that
>> people stop using 'cond' and start using 'pcase' instead.  A few
>> examples:
>>
>> todo-mode.el:
>>
>>     (pcase this-param
>>       ('edit (todo-edit-item--text))
>>       ('header (todo-edit-item--text 'include-header))
>>       ('multiline (todo-edit-item--text 'multiline))
>>       ('add/edit (todo-edit-item--text 'comment-edit))
>>       ('delete (todo-edit-item--text 'comment-delete))
>>       ('diary (todo-edit-item--diary-inclusion))
>>       ('nonmarking (todo-edit-item--diary-inclusion 'nonmarking))
>>       [...]
>>
>> auth-source-pass.el:
>>
>>     (pcase (length matching-entries)
>>       (0 (auth-source-pass--do-debug "no match found")
>>          nil)
>>       (1 (auth-source-pass--do-debug "found 1 match: %s" (car 
>> matching-entries))
>>          (car matching-entries))
>>       (_ (auth-source-pass--select-one-entry matching-entries user)))))
>>
>> bs.el:
>>
>>            (setq bs-buffer-show-mark (pcase bs-buffer-show-mark
>>                                        (`nil   'never)
>>                                        (`never 'always)
>>                                        (_       nil))))))
>>
>> calculator.el:
>>
>>                (<= inp (pcase calculator-input-radix
>>                          (`nil ?9) (`bin ?1) (`oct ?7) (_ 999))))
>>
>> lpr.el:
>>
>>                  (pcase (count-lines (point-min) (point-max))
>>                    (0 "")
>>                    (1 ": ")
>>                    (_ ":\n"))
>
> FWIW, these are the major cases I wanted to treat, but I wanted to
> replace them with equivalent cl-case forms, not with `cond's.
>
>> (Quick: what's the difference between `require and 'require in this
>> case?)
>
> There is none any more.
>
>> easy-mmode.el:
>>
>>       (pcase keyw
>>      (`:group (setq group (nconc group (list :group (pop keys)))))
>>      (`:global (setq keys (cdr keys)))
>>      (_ (push keyw extra-keywords) (push (pop keys) extra-keywords))))
>>
>> (Aren't keywords supposed to be self-quoting? then why they are
>> explicitly quoted?)
>
> Yes.
>
>> We have dozens of such fragments in our codebase, which just makes the
>> sources harder to read, especially for people who aren't fluent with
>> 'pcase' (which seems to be the case with many of us).
>
> These are all cases I would want to fix, but unless the whole pcase form
> can be trivially rewritten as cl-case, I want to leave pcase, really.

I’d prefer much this, as I find `case' well much less redundant, it’s
just basic factorization.  Programming is here to factorize, so it
should be factorized.  Even C do that.  Case is the simpler, most
obvious and straightforward to factorize a lot of cond (it is a shame we
don’t have it with equal, some case* or case-equal would be
appreciated).



reply via email to

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