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: Stephen Berman
Subject: Re: Replace trivial pcase occurrences in the Emacs sources
Date: Thu, 25 Oct 2018 09:17:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Wed, 24 Oct 2018 16:52:23 -0400 Stefan Monnier <address@hidden> wrote:

>>     (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))
>>       [...]
>
> Is the below any better?
>
>     (cond
>       ((eq this-param 'edit) (todo-edit-item--text))
>       ((eq this-param 'header) (todo-edit-item--text 'include-header))
>       ((eq this-param 'multiline) (todo-edit-item--text 'multiline))
>       ((eq this-paran 'add/edit) (todo-edit-item--text 'comment-edit))
>       ((eq this-parom 'delete) (todo-edit-item--text 'comment-delete))
>       ((eq this-param 'diary) (todo-edit-item--diary-inclusion))
>       ((eq this-param 'nonmarking) (todo-edit-item--diary-inclusion 
> 'nonmarking))
>       [...]
>
> To me, it's more verbose and more complex because you need to double
> check that the same var is tested each time before you can know that it's
> equivalent to a C-style `switch`.
>
> IOW, I consider rewriting the `cond` to use `pcase` to be a form of
> "common sub-expression elimination", or reduction of copy&paste.

FWIW, this is basically the reason I used pcase instead of cond in the
above code, it wasn't just to jump on the pcase bandwagon (and it didn't
occur to me at the time to use cl-case).

Steve Berman



reply via email to

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