< Back to IRCAM Forum

Adding inputs to defmethod

Hello,
I’m having problems adding inputs to a lisp method without renaming the function. Lets take the example from the documentation page for user libraries:

(defmethod! Addition ((self list) (arg1 number))
:initvals '( 10 10 )
:indoc '(“First operand” “Second operand” )
:icon '(176)
:doc “Adds 2 things. Things can be numbers, lists, chords.”
(+ self arg1 ) )

I type option-y and test the function. Now I want to have more inputs, and type:

(defmethod! Addition ((self list) (arg1 number) (arg2 number))
:initvals '( 10 10 )
:indoc '(“First operand” “Second operand” )
:icon '(176)
:doc “Adds 2 things. Things can be numbers, lists, chords.”
(+ self arg1 ) )

When I try to evalute this, I get the error:
ERROR: Lambda list (self arg1 arg2) is not congruent with the lambda list (self arg) of #<omgenericfuntion addition 29C9BF0A>
But if I change the name of the method, it works:

(defmethod! Addition-3in ((self list) (arg1 number) (arg2 number))
:initvals '( 10 10 )
:indoc '(“First operand” “Second operand” )
:icon '(176)
:doc “Adds 2 things. Things can be numbers, lists, chords.”
(+ self arg1 ) )

It seems you always have to change the name if you want to redefine number of inputs. Indoc and intivals doesn’t seem to matter for the evaluation. I had problems working on a different function and tried a simple example. Do you know why it acts this way?

I also had problems adding :doc while keeping multiple outputs of a method, so I ended up removing the documentation. I should try to isolate this problem and give an example.

I’m still using Om 6.9.

Ruben

Redefining a method while changing num of arguments, you will have indeed this prob.
Using (fmakunbound 'Addition) will unbound the method and you can restart again.
But remember you cannot have the same method with diff number of arguments each time. It should have ALWAYS the same num of arguments even if some of them you don’t use.

Hope this helps.

best
K

Hi,
I’m having a problem creating a method with 2 optional inputs. The method below is created to add icon and documentation to a function.
It works in the function (defun) “r-wallin-crystal-chord-function”. If nothing is connected, some results will be nil and removed.
When using it inside a method I get “cannot take car of 0” if inputs 4 or 5 are missing. Is there a way to make set nil as default? I tried with :initvals, but it didn’t help so far.
Ruben

(defmethod! r-wallin-crystal-chord

                   ((1-basenote-list list) (germ-intervals-list list) (index-repeats-1st-level-lists list)   
                    (index-repeats-2nd-level-lists list)(germ-index-for-all-index list ))  

:initvals '((0)(0)(0) nil nil)
:indoc '(“1-basenote-list” “germ-intervals-list” “index-repeats-1st-level-lists”
“index-repeats-2nd-level-lists” “germ-index-for-all-index”)
:icon 708

;Redefine functions as methods to include documentation and icon
(r-wallin-crystal-chord-function 1-basenote-list germ-intervals-list index-repeats-1st-level-lists
index-repeats-2nd-level-lists germ-index-for-all-index)
)

yes because your two last inputs are not optional.
If you need them to be you should do this :
(defmethod! r-wallin-crystal-chord ((1-basenote-list list)
(germ-intervals-list list)
(index-repeats-1st-level-lists list)
&optional
(index-repeats-2nd-level-lists nil)
(germ-index-for-all-index nil))
…etc…
)

maybe this is what you want, since you’ve send part of a code…

BEst
K

Thank you, I tried that now, but it doesn’t work yet. Even when commenting out :initvals and :indoc and restarting Open Music, I still get (0) instead of nil from an empthy input. I can use the function version where I want it to be optional though.
Best
Ruben