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

Bug(?) in defmeth and number of arguments



It appears that you cannot have methods with the same name but different
numbers of arguments.  For example, CommonLoops will not work with the
following defmeths.

(defmeth move ((self window) (x integer) (y integer)) ...

(defmeth move ((self window) (pos position))

It doesn't work with the followwing defmeths either (in case you thought
it had something to do with common first arg type)

(defmeth move ((self window) (x integer) (y integer)) ...

(defmeth move  ((self 3d-window) (x integer) (y integer) (z integer)) ...


What PCL does is it uses only methods with the same number of args as
the method with the minimum number of args defined so far.  All other
methods are ignored.

So, if you define a 3 arg method, the method will work until you define
a 1 or 2 arg method.  When the 1 or 2 arg methods are defined, the 3 or
more arg methods no longer work.  If you define a 2 arg method first, the
3 or more arg methods are never accessable.

Below are examples.  These are from PCL on top of EXCL, but it works
the same in LUCID.  (PCL from 12.02).

geza% excl
Extended Common Lisp 1.3 (11/17/86 14:48)
(c) copyright 1986, Franz Inc., Alameda, Ca 

halasz #1: (defmeth test ((self integer)(arg1 integer)) "two args" "two args")
TEST 

halasz #2: (test 1 1)
"two args" 

halasz #3: (defmeth test ((self symbol)) "one arg" "one arg")
TEST 

halasz #4: (test 1 1)
Error: No matching method for: TEST.
[1] halasz #5: :pop

halasz #6: (test 'A)
"one arg" 

halasz #7: (test 'A 'A)
Continuable Error: EXCL::ANONYMOUS-LAMBDA got 2 args, wanted at most 1.
If continued with :continue, Ignore the extra args.
[1c] halasz #8: :pop

halasz #9: (defmeth test ((self integer)) "one arg 2" "one arg 2")
TEST 

halasz #10: (test 1)
"one arg 2" 

halasz #11: (test 1 1)
Continuable Error: EXCL::ANONYMOUS-LAMBDA got 2 args, wanted at most 1.
If continued with :continue, Ignore the extra args.
[1c] halasz #12: :pop

halasz #13: (defmeth test ((self list )(arg1 list))"one arg 3" "one arg 3")
TEST 

halasz #14: (test (LIST 1)(LIST 3))
Error: No matching method for: TEST.


-- Frank
--
------------------------------------------------------------

Frank Halasz          
MCC Software Technology
9390 Research Blvd
Austin TX 78759.
[512]338-3648 

halasz@MCC.COM
or {harvard,ihnp4,nike,seismo}!ut-sally!im4u!milano!halasz