unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
	Ag Ibragimov <agzam.ibragimov@gmail.com>,
	emacs-devel@gnu.org
Subject: Re: Pattern matching on match-string groups #elisp #question
Date: Sat, 27 Feb 2021 11:17:55 +0100	[thread overview]
Message-ID: <288FFC66-E3BE-4E5F-AAD5-309A632F8058@acm.org> (raw)
In-Reply-To: <jwvv9aeabdr.fsf-monnier+emacs@gnu.org>

26 feb. 2021 kl. 20.38 skrev Stefan Monnier <monnier@iro.umontreal.ca>:

> BTW, I was thinking about making the optimization more conservative, so
> it only throws away the actual `if` but keeps the computation of the test:
[...]
> and it does fix the `pcase-let` problem with your original code.

Given the trouble I think we can defend not respecting side-effects in something as functional as pcase!

> It should macroexpand to something morally equivalent to:
> 
>    (cond ((not (stringp STR)) nil)
>          ((not (string-match "\\(?1:a*\\)" STR)) nil)
>          ((looking-at "^"")
>           (let* ((x1464 (match-string 1 STR)))
>             (let ((FOO x1464)) FOO))))

Oh dear... perhaps we should just go with the intermediate list (or vector) and suffer the small allocation penalty? (At least we should treat the case of a single variable specially, since no consing would then be necessary.)

My guess is that a vector may be faster than a list if there are more than N elements, for some N.
Should we use string-match-p when there are no variables bound in the rx clause?

>> Of course a sufficiently optimising compiler would eliminate the consing!
> 
> Indeed, and it's not a difficult optimization (at least if you can
> presume that this data is immutable).

Right, although we would need some more serious data-flow infrastructure first. It would be useful for pattern-matching two or more values at the same time.

>>> It's linked to the special undocumented pcase pattern `pcase--dontcare`
>>> (whose name is not well chosen, suggestions for better names are
>>> welcome)
>> 
>> pcase--give-up
> 
> Hmm... probably not much more explanatory than "dontcare".

Well, 'dontcare' suggests that anything would do and the value not being used, like '_', but that's quite misleading.

> I was thinking of `pcase--impossible` as well.

Yes, that looks acceptable. In any case, it isn't really a user-facing symbol, is it? Otherwise we'd need crystal-clear semantics (and lose the double dashes).




  reply	other threads:[~2021-02-27 10:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25  5:11 Pattern matching on match-string groups #elisp #question Ag Ibragimov
2021-02-25 14:55 ` Basil L. Contovounesios
2021-02-25 15:32   ` Stefan Monnier
2021-02-25 18:28     ` Mattias Engdegård
2021-02-26  4:31       ` Stefan Monnier
2021-02-26 10:24         ` Mattias Engdegård
2021-02-26 19:38           ` Stefan Monnier
2021-02-27 10:17             ` Mattias Engdegård [this message]
2021-02-27 14:39               ` Stefan Monnier
2021-02-27 18:10                 ` Mattias Engdegård
2021-02-27 20:32                   ` Stefan Monnier
2021-02-28 13:46                     ` Mattias Engdegård
2021-02-28 15:37                       ` Stefan Monnier

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=288FFC66-E3BE-4E5F-AAD5-309A632F8058@acm.org \
    --to=mattiase@acm.org \
    --cc=agzam.ibragimov@gmail.com \
    --cc=contovob@tcd.ie \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).