GNU bug report logs -
#68029
29.1; (elisp) `pcase Macro': misleading mention of `cl-case'
Previous Next
Reported by: Drew Adams <drew.adams <at> oracle.com>
Date: Mon, 25 Dec 2023 16:27:02 UTC
Severity: normal
Found in version 29.1
Done: Stefan Kangas <stefankangas <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#68029: 29.1; (elisp) `pcase Macro': misleading mention of `cl-case'
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 68029 <at> debbugs.gnu.org.
--
68029: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68029
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Drew Adams <drew.adams <at> oracle.com> writes:
> 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.
This shows that you do need to use a `code' variable (you named it `val'
though), and that the pcase version is indeed better.
> 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.
No, the reality is that `pcase' has *many* advantages over `cl-case'.
The example is just intended to showcase some of them.
> 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")))))
I'm not sure that's indeed easier for a beginner ELisp developer to
follow. So I don't think it's worth making that change.
> (And you've presumably misspelled schmilblick ;-):
> https://en.wikipedia.org/wiki/Schmilblick)
I don't follow, sorry.
So I'm closing this bug report.
[Message part 3 (message/rfc822, inline)]
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)
This bug report was last modified 1 year and 197 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.