emacs-devel
[Top][All Lists]
Advanced

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

RE: [External] : Re: cond* vs pcase


From: Adam Porter
Subject: RE: [External] : Re: cond* vs pcase
Date: Tue, 6 Feb 2024 14:08:59 -0600
User-agent: Mozilla Thunderbird

It says, in effect, "This just tests the
value for simple equality (using this or
that equality predicate)."  It speaks
quietly, humbly, clearly. >
`pcase' advertises instead: "Here come the
Big Guns, which can wrestle _anything_ to
the ground!  Stand in awe and wonder."

CL-CASE and PCASE neither say nor advertise anything. They have no personal qualities. They are macros, not people.

  (pcase foo
    ('bar (do-some-bar-stuff))
    ('baz (do-some-baz-fluff)))

is not more awful or wonderful than:

  (cl-case foo
    (bar (do-some-bar-stuff))
    (baz (do-some-baz-fluff)))

And neither of them is worse than what they expand to:

  (cond ((eql foo 'bar)
         (do-some-bar-stuff))
        ((eql foo 'baz)
         (do-some-baz-fluff)))

Nor is this:

  (pcase foo
    (1 'ONE)
    (2 'TWO)
    ((cl-type function) (funcall foo))
    (_ 'SOMETHING-ELSE))

any worse than what it expands to:

  (cond ((eql foo 1)
         'ONE)
        ((eql foo 2)
         'TWO)
        ((cl-typep foo 'function)
         (funcall foo))
        (t
         'SOMETHING-ELSE))

That example is not even a case of pattern-matching, as no patterns are involved.

But if one needed to add a pattern, as in the common case of a customization option having various possible value types, one may easily do so, as in:

  (pcase foo
    (1 'ONE)
    (2 'TWO)
    ((cl-type function) (funcall foo))
    (`(,fn . ,arg) (funcall fn arg))
    (_ 'SOMETHING-ELSE))

I cannot fathom how this optionally available "power" is a problem which should consign PCASE to only exceptional cases, any more than Lisp's power should consign it to only a few libraries, leaving the rest to be implemented in lower-level languages; or any more than Emacs's power should consign it to only a few use cases, leaving the the rest to be implemented in utilities to be piped together in a shell.



reply via email to

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