emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pcase defuns


From: Stefan Monnier
Subject: Re: pcase defuns
Date: Tue, 21 Dec 2021 10:32:40 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> Great points, thank you! Indeed, both of these wouldn't work - I'm just
> quoting and storing the function body for later.  I'll have to think about
> whether there is something more clever I can do that would fix
> these problems.

You could put the bodies into auxiliary functions (which then get
compiled in the usual way) and only quote&store the "pattern +
auxiliary-function-name".  That should get you much cleaner semantics
already (might be sufficient for the examples I showed).  It still would
have odd corner cases when you have code in the patterns or when the
patterns use pcase patterns defined in a file loaded via
`eval-when-compile` (the latter can be handled by pre-expanding the
patterns via `pcase--macroexpand` before you quote&store).

> Does every defun-like thing obey these rules?

That's not really the question.  The question is rather what should your
code do in those cases, and how do you document it.

BTW, regarding the problem of ordering, an easy way out is to pass the
ball to the programmer: use a syntax like (pcase-defun NAME PRIO (ARGS) BODY)
where PRIO is a number giving the "priority" of the rule; then you just
order the rules by priority.

That's what I did in `cl-generic-generalizers`, in `add-function`, and
in `add-hook` ;-)


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]