emacs-devel
[Top][All Lists]
Advanced

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

Re: pcase defuns


From: Andrew Hyatt
Subject: Re: pcase defuns
Date: Sun, 17 Apr 2022 18:09:24 -0400

On Thu, Mar 31, 2022 at 12:27 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. ]]] > 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. The argument list is not just a concept in users' minds. The command C-h f, which shows documentation for a function, displays the function's argument list. If you try C-h f cons RET, you'll see what I mean. See also `func-arity'. So there is a practical reason for defining constructs to set up the function's argument list. > In particular, with your proposal, we lose the ability to > have fairly different arg patterns, with different numbers > of args, or different destructuring patterns. Not necessarily. You could specify `&rest args' for an arglist that conveys no information. But users find it useful to see in a simple way what the arguments of the function should be.

Thanks for the suggestion. I've implemented a new version along the lines you suggested. So now things look like:

(defun-pattern fibonacci (n)
   "Compute the fibonacci sequence."
       (0 0)
       (1 1)
       (n
           (+ (fibonacci (- n 1))
                (fibonacci (- n 2)))))

and

(defun-pattern repeatedp (&rest args)
"Test for repeated pattern, returns nil, 'once, or 'twice, or 'split."
   ((a a) 'once)
   ((a a a) 'twice)
   ((a b a) 'split))

With this, I think I've answered your objections.  Do you have an
opinion on what I should do with this?  I can check this in the emacs
source code, as a GNU elpa package, or just put it in an external repository.


--
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)



reply via email to

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