unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Adam Porter <adam@alphapapa.net>
Cc: "ams@gnu.org" <ams@gnu.org>,
	"arthur.miller@live.com" <arthur.miller@live.com>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>,
	"philipk@posteo.net" <philipk@posteo.net>
Subject: RE: [External] : Re: cond* vs pcase
Date: Tue, 6 Feb 2024 23:32:25 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488EDAD5C20C8BA44A4A6B1F3462@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <822c332c-1a85-4454-8978-0b1491981058@alphapapa.net>

>    (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)))

Exactly.  The difference is tiny when the
two are, uh, doing the same thing.

When `pcase' is used only to do what
`cl-case' is designed for, it doesn't
proclaim immediately to readers that
that's all it's doing.
___

However, our doc actually claims that a
`pcase' version of a similar example is
_superior_ to `cl-case' (not just-as-good).

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68029

 "This shows that you do need to use a `code'
  variable (you named it `val' though), and
  that the pcase version is indeed better."

(The `pcase' example actually uses _more_
variables than the `cl-case' example, in
spite of the doc claiming that it's better
because it uses fewer.)

If our doc and a maintainer can mistakenly
think `cl-case' is required to bind more
vars in such an example, then imagine how
mixed up a reader might be.

The point about using `cl-case' (or `cond'
or whatever else) in particular cases (vs
rather, using `pcase' in other cases) is
that doing so conveys the info that we're
talking about a simple or a not-so-simple
case.

If you use `pcase' for something for which
`cl-case' easily suffices, that can be less
clear than reserving `pcase' for heavier
lifting (when it's really needed).

Using them both, each for what it can offer,
can elucidate just what work is involved.

> 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))

Of course.  Did someone argue that `pcase'
doesn't compile or macroexpand to efficient
code?

It's a style/messaging question.  Using
`pcase' for what `cl-case' can't do easily
and clearly can then say, "This here ain't
a straightforward `cl-case' thing."

You don't have to adopt such a convention.
But you can.  Then when your readers see
`pcase' they'll pay attention, looking for
what _particularly called for_ using it.

>    (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

No one suggested that.  Saying that it can
help to use `cl-case' when it perfectly fits
the bill is not the same as saying that one
should always use `cl-case'.

The argument is against always using `pcase';
it's not for always using `cl-case' (or `cond'
or...).

Use each for what it can do well/better.  And
yes, it's only about coding style; it's not
about performance differences.  (Maybe ask
yourself why you'd think the question is about
performance?)
  
> 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.

That's precisely the point.  One size might
stretch to fit all, but it's not necessarily
the best fit for everything.

Don't use a jackhammer to drive in a carpet
tack, if you have a tack hammer in your tool
belt.  (But sure, you can always use the
jackhammer if you really want.)

  reply	other threads:[~2024-02-06 23:32 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 14:30 cond* vs pcase Arthur Miller
2024-02-05 15:13 ` Eli Zaretskii
2024-02-05 16:06 ` Alfred M. Szmidt
2024-02-05 18:39   ` Philip Kaludercic
2024-02-06 12:30     ` Arthur Miller
2024-02-06 16:17     ` Alfred M. Szmidt
2024-02-06 16:35       ` [External] : " Drew Adams
2024-02-06 16:50       ` Philip Kaludercic
2024-02-06 17:27         ` Alfred M. Szmidt
2024-02-06 18:57           ` Philip Kaludercic
2024-02-06 19:04             ` Alfred M. Szmidt
2024-02-06 19:39               ` Philip Kaludercic
2024-02-06 23:17                 ` [External] : " Drew Adams
2024-02-06 19:12             ` Drew Adams
2024-02-06 20:08               ` Adam Porter
2024-02-06 23:32                 ` Drew Adams [this message]
2024-02-07 13:14                   ` Arthur Miller
2024-02-07 13:43                     ` Po Lu
2024-02-07 17:09                       ` Drew Adams
2024-02-07 17:44                       ` Tomas Hlavaty
2024-02-09  3:52                         ` Richard Stallman
2024-02-07 18:00                       ` Arthur Miller
2024-02-07 18:22                         ` Alfred M. Szmidt
2024-02-08  1:55                           ` Po Lu
2024-02-08  2:49                             ` Philip Kaludercic
2024-02-08  3:36                               ` Po Lu
2024-02-08  7:04                             ` Eli Zaretskii
2024-02-08 17:01                               ` Alfred M. Szmidt
2024-02-08 17:01                             ` Alfred M. Szmidt
2024-02-09  1:30                               ` Po Lu
2024-02-08  5:01                         ` Po Lu
     [not found]                           ` <DU2PR02MB10109B7AC39F995BFE266EF5396442@DU2PR02MB10109.eurprd02.prod.outlook.com>
2024-02-08  7:36                             ` Sv: " Arthur Miller
2024-02-12 21:39                       ` Stefan Monnier via Emacs development discussions.
2024-02-07 17:14                     ` Drew Adams
2024-02-07  5:32             ` Yuri Khan
2024-02-07 12:43               ` Arthur Miller
2024-02-07 17:41                 ` Alfred M. Szmidt
2024-02-07 18:36                   ` Arthur Miller
2024-02-07 19:12                     ` Alfred M. Szmidt
2024-02-07 21:20                       ` Arthur Miller
2024-02-06 17:29         ` [External] : " Drew Adams
2024-02-06 17:41           ` Alfred M. Szmidt
2024-02-06 17:50         ` Thierry Volpiatto
2024-02-06 19:04           ` Alfred M. Szmidt
2024-02-07 15:03           ` Barry Fishman
2024-02-07 17:22             ` [External] : " Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SJ0PR10MB5488EDAD5C20C8BA44A4A6B1F3462@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=adam@alphapapa.net \
    --cc=ams@gnu.org \
    --cc=arthur.miller@live.com \
    --cc=emacs-devel@gnu.org \
    --cc=philipk@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).