Sujet : Math operation abstraction
De : dan.list (at) *nospam* lispclub.com (Daniel Cerqueira)
Groupes : comp.lang.lispDate : 28. May 2024, 00:29:56
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87fru251nf.fsf@lispclub.com>
User-Agent : Gnus/5.13 (Gnus v5.13)
Hi.
I have this function
```
(defun muo (func a b)
(cond
((eq b 1) a)
(t (funcall func a (muo func a (1- b))))))
```
Which I can use for obtaining the multiplication operation using the
addition. As an example:
* (muo #'+ 5 2)
10
and "muo #'+" means "use the multiplication".
Now if I want the exponentiation I have to do:
* (muo #'(lambda (a b) (muo #'+ a b)) 5 2)
25
This creates the exponentiation.
I would like to obtain the exponentiation using "(muo #'+ 5 2 2)"
instead, being the last argument ("2") the number of times the operation
is applied. In the case of exponentiation, it applies the multiplication
2 times, resulting in the exponentiation math operation.
I am hoping I am explaining this concept well enough.
Basically, "muo #'+" creates the addition twice, which is the
multiplication, and "muo #'+ a b 2" should create the multiplication
twice, which is the exponentiation. If I use "muo #'+ a b 3" it should
create the exponentiation twice, which is the exponentiation of the
exponentiation.
I need help in making this code modification. Seeing code is what I
want. If you can write the code and explain it, better.