Next: , Previous: , Up: Methods and Generic Functions   [Contents][Index]


8.6.5 method* and define-method*

method* and define-method* are the GOOPS versions of lambda* and define*.

syntax: method* ([param…]
[#:optional vardef…]
[#:key vardef… [#:allow-other-keys]]
[#:rest var | . var])
body1 body2 …

Create a method which takes optional and/or keyword arguments specified with #:optional and #:key. See lambda* and define*.. param… are ordinary method parameters as for method and define-method, i.e. either var or (var typespec).

define-method* is syntactic sugar for defining methods using method*. For example,

(define-method* (foo (a <integer>) b #:optional c
                     #:key (d 2) e
                     #:rest f)
  (list a b c d e f))

is a method with fixed arguments a of type <integer> and b of type <top>, optional argument c, keyword arguments d, with default value 2, and e, and rest argument f. A call

(foo 1 'x #:d 3 'y)

will return

(1 x #f 3 #f (#:d 3 y))

The values for c and e are #f since they have not been given in the call. The given keyword argument(s) are included in the rest argument, as for define*.