unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 68029@debbugs.gnu.org
Subject: bug#68029: 29.1; (elisp) `pcase Macro': misleading mention of `cl-case'
Date: Mon, 25 Dec 2023 16:26:22 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488F7860DBCDDB20B9EB259F399A@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)

I find this comment misleading/incorrect:

  With 'cl-case', you would need to explicitly declare a local variable
  'code' to hold the return value of 'get-return-code'.  Also 'cl-case' is
  difficult to use with strings because it uses 'eql' for comparison.

In fact, with `cl-case' the code is at least as simple:

(let* ((val (get-return-code x))) 
  (if (stringp val)  (message val)
    (cl-case val
      (success       (message "Done!"))
      (would-block   (message "Sorry, can't do it now"))
      (read-only     (message "The shmliblick is read-only"))
      (access-denied (message "You do not have the needed rights"))
      (val           (message "You do not have the needed rights")))))

Yes, it's true that comparison is with `eql', so for a string value you
need to test that separately (or intern and then test symbols with
`cl-case').  But there's no need to use any `code' variable.

If you can't come up with a better example to show advantages of `pcase'
over `cl-case' (and that should be easy to do), then don't say anything
about `cl-case'.  Or maybe just tell the truth: `cl-case' handles _one
simple `pcase' use case_ in a simpler way.  IOW, if you're just testing
equality of the expression's value against particular symbols then
`cl-case' is simpler and clearer.

Even clearer is just this (same for the `pcase' example):

(message
 (let* ((val (get-return-code x))) 
   (if (stringp val) val
     (cl-case val
       (success       "Done!")
       (would-block   "Sorry, can't do it now")
       (read-only     "The shmliblick is read-only")
       (access-denied "You do not have the needed rights")
       (val           "You do not have the needed rights")))))

(And you've presumably misspelled schmilblick ;-):
https://en.wikipedia.org/wiki/Schmilblick)

In GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-08-02 built on
 AVALON
Windowing system distributor 'Microsoft Corp.', version 10.0.19045
System Description: Microsoft Windows 10 Pro (v10.0.2009.19045.3803)

Configured using:
 'configure --with-modules --without-dbus --with-native-compilation=aot
 --without-compress-install --with-tree-sitter CFLAGS=-O2'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XPM ZLIB

(NATIVE_COMP present but libgccjit not available)






             reply	other threads:[~2023-12-25 16:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-25 16:26 Drew Adams [this message]
2023-12-25 16:53 ` bug#68029: 29.1; (elisp) `pcase Macro': misleading mention of `cl-case' Stefan Kangas
2023-12-26 17:46   ` 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=SJ0PR10MB5488F7860DBCDDB20B9EB259F399A@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=68029@debbugs.gnu.org \
    /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).