help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: [External] : Re: Emacs 30.0 warning from `cl-pushnew' and `memql'


From: Drew Adams
Subject: RE: [External] : Re: Emacs 30.0 warning from `cl-pushnew' and `memql'
Date: Thu, 29 Dec 2022 22:00:50 +0000

> > Oh, you meant that the simpler `case' syntax might
> > be harder for some of the people who are used to
> > the more complex syntax of `pcase', where you need
> > to quote symbols as values to be compared.
> 
> No, I mean that even for some people unfamiliar with `pcase` syntax, the
> `pcase` syntax is simpler (more natural?) than the cl-`case` syntax: the
> incorrect use of `quote` in `cl-case` predates the invention of `pcase`
> :-)

I think you'll need to explain your "incorrect use of
`quote' in `cl-case'".  There's no particular use of
`quote' or quoting in `case'.

Are you saying you think `case' should require users
to quote symbols to test for eqlity, i.e., that CL
should have defined `case' so that you need to use

(case FOO
  ('a             "AAA")
  (42             (value-for-42)) ; Or maybe use '42?
  (('c 'd 'e)     (value-for-C-D-or-E))
  (('f 'quote)    (value-for-F-or-QUOTE))
  ...)

instead of this?

(case FOO
  (a             "AAA")
  (42            (value-for-42))
  ((c d e)       (value-for-C-D-or-E))
  ((f quote)     (value-for-F-or-QUOTE))
  ...)

If so, why?

> >> > IOW, I don't argue that we shouldn't have `pcase'.
> >> > I don't see why we shouldn't also have `case'
> >> > (sans `cl-'), that's all.
> >> What's the benefit (other than having to learn 2
> >> subtly different things instead of just one)?
> > Simpler, for simple cases.
> 
> I don't think `case` is objectively simpler.

Please show us an example where `pcase' does
only what `case' does, but with simpler syntax.

> More specifically, I believe that if you're familiar
> with neither `cl-case` nor `pcase` syntax, it's not
> easier to learn the `case` syntax than the subset of
> `pcase` syntax which covers the functionality of `cl-case`.

1. It's easier to learn, if only because you
don't have to ALSO learn the non-`case' cases
that `pcase' syntax covers - including patterns
that both bind and match, etc.

You need to at least learn enough of that other
stuff to be able to _not_ fall into it when
you're trying to do just what simple `case'
does: test a value against some atomic values.

2. It's easier to use, for the same reason.

> It may even be objectively easier to learn the
> `pcase` syntax since it doesn't suffer from
> special cases like when you want to distinguish
> one of the `nil`, `t`, or `otherwise` values.

You pepper repeat "objectively", but isn't that
gratuitous?  Saying it's so doesn't make it so.
Show da codes, please.

`t' means the same thing as in `cond'.  Is it
really hard to grasp?  And to be "nicer", `case'
also gives you the synonym `otherwise', which
SHOUTS its meaning of "default", no?

And you can always just use a list for the test
values, including a singleton list.  Nothing
obliges one to take advantage of the shorthand
of using just b instead of (b). KISS: always a
list of things to match, or else `otherwise'
for no matches:

(case FOO
  ((a)           "AAA")
  ((nil)         "NIL")
  ((t)           "T")
  ((otherwise)   "Symbol `otherwise'")
  ((c d e)       "C, D, or E")
  ((f quote)     "F-or-QUOTE")
  (otherwise     "Anything else (default)"))

Sure, the simple, general syntax of using a list
of things to match means that () or nil as the
_list_ of values to match can never match (no
list elements to match).  Is that too complex?
It's something Lisp users are used to, no?  Even
novice Lisp users learn early on that nil/() is
both a list and a symbol.  `case' isn't the only
place where this needs to be understood.

It's common in Lisp programs to distinguish an
empty list of values from a single nil value
(whether viewed as symbol or empty list), by
wrapping the latter in a cons: (nil).

And always using an explicit list of things to
match (or else the atom `otherwise') makes it
very clear that () or nil as that list is useless
- no thing matches nothing.  If you really think
some users have trouble with the `case' syntax
then just tell 'em to always use a list of things
to match.

Which (`case' or `pcase') seems simpler might be
just a personal preference on each of our parts.

Lisp provides many ways to do the same thing,
including multiple control constructs (as I
mentioned, and about which you apparently had
nothing to say).

That `pcase' can do what `case' does isn't an
argument for not including `case' in Elisp.
Look at all of the `*-let' stuff that's been
added to Elisp over the last few years.  Really
needed?  Clearly someone thought that was all
useful for some users...

<<attachment: winmail.dat>>


reply via email to

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