From: Andrew Hyatt <ahyatt@gmail.com>
To: rms@gnu.org
Cc: emacs-devel@gnu.org
Subject: Re: pcase defuns
Date: Tue, 29 Mar 2022 21:28:00 -0400 [thread overview]
Message-ID: <m2fsn0grfj.fsf@andrews-mbp.lan> (raw)
In-Reply-To: <E1nYgnA-000696-5m@fencepost.gnu.org>
On Mon, Mar 28, 2022 at 12:15 AM Richard Stallman <rms@gnu.org>
wrote:
> [[[ To any NSA and FBI agents reading my email: please consider
> ]]] [[[ whether defending the US Constitution against all
> enemies, ]]] [[[ foreign or domestic, requires you to follow
> Snowden's example. ]]]
>
> > To give a flavor of what it looks like in practice, here's a
> > few pattern defuns from the test:
>
> > (defun-pattern fibonacci
> > "Compute the fibonacci sequence."
> > ((0) 0) ((1) 1) ((n)
> > (+ (fibonacci (- n 1))
> > (fibonacci (- n 2)))))
>
> For defining how to compute the value, it is clear and simple.
> (Do the patterns handle decomposing lists and other compound
> objects?)
Yes, it does this.
> But defining how to compute the value is not the only job a
> defun needs to do. It also needs to record argument names.
The way I look at it, it does do this, but it's just structured
differently. The normal defun as one arglist. Mine has one per
matching clause, which means that it can take a variety of
different arguments, all matching. And the arglist and the
matching clauses are the same thing, so the arglist can be (n), or
('foo n), or (1 2 (3 n)), etc. Yes, it's weird, but I think the
differentiation here is useful, see my next point.
> Also, it doesn't seem to offer a way to make the function accept
> other arguments beyond the one that the pattern will be applied
> to.
>
> So I think it should take an argument list, and bind all the
> argument variables, like this:
>
> (defun-pattern fibonacci (n)
> "Compute the Nth fibonacci number."
> ((0) 0) ((1) 1) (t
> (+ (fibonacci (- n 1))
> (fibonacci (- n 2)))))
>
> (defun-pattern sum (x y)
> "Compute the sum of natural numbers X and Y."
> ((0) y) (t
> (1+ (add (1- x) y))))
Thank you for the feedback and your examples.
There's a tension here: if I make this fit more with existing
patterns, it becomes something that seems closer to just a defun
with a pcase in it. Maybe a bit cleaner. In particular, with your
proposal, we lose the ability to have fairly different arg
patterns, with different numbers of args, or different
destructuring patterns. However, I admit that my proposal, without
a single arglist, is odd, and may be seen as too esoteric by most.
I'm curious to hear more opinions.
>
> --
> Dr Richard Stallman (https://stallman.org)
> Chief GNUisance of the GNU Project (https://gnu.org)
> Founder, Free Software Foundation (https://fsf.org)
> Internet Hall-of-Famer (https://internethalloffame.org)
next prev parent reply other threads:[~2022-03-30 1:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-19 4:53 pcase defuns Andrew Hyatt
2021-12-19 8:34 ` Tassilo Horn
2021-12-19 15:33 ` Andrew Hyatt
2021-12-19 17:16 ` Tassilo Horn
2021-12-19 19:05 ` Stefan Monnier
2021-12-20 5:56 ` Tassilo Horn
2021-12-22 14:07 ` LdBeth
2021-12-19 17:23 ` Stefan Monnier
2021-12-19 21:08 ` Andrew Hyatt
2021-12-21 4:15 ` Richard Stallman
2021-12-21 5:20 ` Andrew Hyatt
2021-12-22 4:18 ` Richard Stallman
2021-12-23 1:52 ` Andrew Hyatt
2021-12-24 4:13 ` Richard Stallman
2021-12-21 15:32 ` Stefan Monnier
2021-12-20 4:43 ` Richard Stallman
2021-12-23 2:30 ` Po Lu
2022-03-26 17:41 ` Andrew Hyatt
2022-03-27 9:31 ` Stefan Monnier
2022-03-27 18:17 ` Andrew Hyatt
2022-03-28 4:15 ` Richard Stallman
2022-03-30 1:28 ` Andrew Hyatt [this message]
2022-03-31 4:27 ` Richard Stallman
2022-04-17 22:09 ` Andrew Hyatt
2022-04-19 3:48 ` Richard Stallman
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=m2fsn0grfj.fsf@andrews-mbp.lan \
--to=ahyatt@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=rms@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).