From: "Ludovic Courtès" <ludo@gnu.org>
To: Simon Tournier <zimon.toutoune@gmail.com>
Cc: Guix Devel <guix-devel@gnu.org>
Subject: Re: ice-9 match penalty depending on pattern?
Date: Sat, 24 Feb 2024 17:27:27 +0100 [thread overview]
Message-ID: <87jzmt7rps.fsf@gnu.org> (raw)
In-Reply-To: <87wmrh6zwl.fsf@gmail.com> (Simon Tournier's message of "Tue, 06 Feb 2024 22:33:46 +0100")
Hey,
Simon Tournier <zimon.toutoune@gmail.com> skribis:
> Re ‘match’ penalty: when using ellipses in patterns, the generated
> code checks for “proper lists”, which is O(n). The trick is to
> instead match a pair:
>
> ✔ (match lst ((head . tail) …))
> ❎ (match lst ((head tail ...) …))
To clarify, my message should not be understood as “never use ellipses
in ‘match’ patterns”.
Whether using ellipses is a “penalty” depends on the context. In some
cases I use ellipses anyway because it’s more accurate, more pleasant to
the eye, because the input list is small, and/or because this is not
performance-critical code.
Having a disjoint type for proper lists would avoid this problem, as I
mentioned on the Fediverse, but we’re not there yet…
Ludo’.
prev parent reply other threads:[~2024-02-24 16:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-06 21:33 ice-9 match penalty depending on pattern? Simon Tournier
2024-02-06 23:41 ` Carlo Zancanaro
2024-02-07 9:22 ` Simon Tournier
2024-02-24 16:27 ` Ludovic Courtès [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://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87jzmt7rps.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guix-devel@gnu.org \
--cc=zimon.toutoune@gmail.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/guix.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).