emacs-devel
[Top][All Lists]
Advanced

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

Re: pcase defuns


From: Richard Stallman
Subject: Re: pcase defuns
Date: Mon, 28 Mar 2022 00:15:44 -0400

[[[ 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?)
But defining how to compute the value is not the only job a defun
needs to do.  It also needs to record argument names.

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

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