chickadee » multi-methods » multi-method-insert!

(multi-method-insert! multi procs key ...)syntax

updates multi's proc-tree at the appropriate argument level. For example, if no key (or a non-existent key) is given, procs is iserted at the very end. If one key is given, procs is inserted before that very key, provided, that key doesn't match multi's and procs' first predicate name. In that latter case, one recurs with appropriate subtrees. Keys are the tags of (possibly compound) type predicates, which are generated automatically from procs by means of internal macros pass and pass*.

procs must be of one of the following forms

;; variadic, not unary
(proc-name ((a a? a1? ...)
            (b b? b1? ...)
            ... : (cs cs? cs1? ...))
           xpr . xprs)

;; variadic unary
(proc-name (as as? as1? ...) xpr . xprs)

;; not variadic
(proc-name ((a a? a1? ...) (b b? b1? ...) ...)
           xpr . xprs)

Note the colon to mark the variadic argument.

Note also, that a variadic argument mustn't be empty, otherwise, there is nothing to dispatch on.

These expressions generate procedures proc-name

(lambda (a b ... . cs) xpr . xprs)

(lambda as xpr . xprs)

(lambda (a b ...) xpr . xprs)

respectively, check their arguments, for example a fixed argument

a by (conjoin a? a1?  ...) named 'a?a1?...

and a variadic argument

cs by (conjoin (list-of? cs?) (list-of? cs1?) ...)

named 'list-of-cs?list-of-cs1? ...

Instead of variables, the predicates can also be nlambda expressions. In any case, the tagging of the compound predicates is done completely behind the scene.