From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Okam <okamsn@protonmail.com>, 49809@debbugs.gnu.org
Subject: bug#49809: [PATCH] Add macro 'pcase-setq'
Date: Thu, 12 Aug 2021 12:13:58 -0400 [thread overview]
Message-ID: <jwveeayy7i4.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87eeb22drs.fsf@web.de> (Michael Heerdegen's message of "Tue, 10 Aug 2021 05:13:11 +0200")
> Undefined behavior has no use per se, unless it has a larger impact on
> efficiency.
There is indeed a significant difference in efficiency.
E.g. the code for (pcase-let ((`(,x ,y) (EXP))) (VAL x y)) looks like:
byte code:
args: nil
0 constant EXP
1 call 0
2 dup
3 car-safe
4 stack-ref 1
5 cdr-safe
6 dup
7 car-safe
8 stack-ref 1
9 cdr-safe
10 stack-ref 3
11 stack-ref 2
12 constant VAL
13 stack-ref 2
14 stack-ref 2
15 call 2
16 return
Instead of:
byte code:
args: nil
0 constant EXP
1 call 0
2 dup
3 consp
4 goto-if-nil-else-pop 3
7 dup
8 car-safe
9 stack-ref 1
10 cdr-safe
11 dup
12 consp
13 goto-if-nil-else-pop 2
16 dup
17 car-safe
18 stack-ref 1
19 cdr-safe
20 dup
21 not
22 goto-if-nil-else-pop 1
25 stack-ref 3
26 stack-ref 2
27 constant VAL
28 stack-ref 2
29 stack-ref 2
30 call 2
31 discardN-preserve-tos 2
33:1 discardN-preserve-tos 2
35:2 discardN-preserve-tos 2
37:3 return
For a semantic where the let is skipped when the pattern fails to match
and
byte code:
args: nil
0 constant EXP
1 call 0
2 dup
3 consp
4 goto-if-nil 3
7 dup
8 car-safe
9 stack-ref 1
10 cdr-safe
11 dup
12 consp
13 goto-if-nil 2
16 dup
17 car-safe
18 stack-ref 1
19 cdr-safe
20 dup
21 goto-if-nil 1
24 stack-ref 4
25 constant error
26 constant "No clause matching `%S'"
27 stack-ref 2
28 call 2
29 return
30:1 stack-ref 3
31 stack-ref 2
32 constant VAL
33 stack-ref 2
34 stack-ref 2
35 call 2
36 return
37:2 stack-ref 2
38 constant error
39 constant "No clause matching `%S'"
40 stack-ref 2
41 call 2
42 return
43:3 dup
44 constant error
45 constant "No clause matching `%S'"
46 stack-ref 2
47 call 2
48 return
For the semantics where we signal an error when the pattern fails to match.
> And why again do you think it is not a good idea?
Because if you want different behaviors when the pattern matches and
when it doesn't, you should use `pcase`.
Stefan
prev parent reply other threads:[~2021-08-12 16:13 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-01 17:20 bug#49809: [PATCH] Add macro 'pcase-setq' Okam via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-04 7:14 ` Lars Ingebrigtsen
2021-08-04 23:06 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-05 1:02 ` Michael Heerdegen
2021-08-05 13:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-05 15:00 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-06 1:42 ` Michael Heerdegen
2021-08-06 4:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-06 4:28 ` Michael Heerdegen
2021-08-06 22:33 ` Okam via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-07 2:11 ` Michael Heerdegen
2021-08-11 21:57 ` Lars Ingebrigtsen
2021-08-12 6:13 ` Michael Heerdegen
2021-08-12 12:11 ` Okam via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-12 15:06 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-13 2:55 ` Michael Heerdegen
2021-08-13 5:17 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-13 5:26 ` Michael Heerdegen
2021-08-07 15:42 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-09 0:28 ` Michael Heerdegen
2021-08-09 12:51 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-10 3:13 ` Michael Heerdegen
2021-08-12 16:13 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
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=jwveeayy7i4.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=49809@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=monnier@iro.umontreal.ca \
--cc=okamsn@protonmail.com \
/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).