Next: , Previous: Generic Dispatch, Up: Generic Dispatch


12.6.1 Generic Procedures

The core of the dispatch mechanism is the generic procedure. This is a procedure that is called in the usual way, but which dispatches to a particular method based on the types of its arguments.

— procedure: make-generic-procedure arity [name]

Returns a new generic procedure accepting arity. Arity must specify a minimum of one argument.

Name is used for debugging: it is a symbol that has no role in the semantics of the generic procedure. Name may be #f to indicate that the generic procedure is anonymous. If name is not specified, it defaults to ‘#f’.

Examples:

          (define foo-bar (make-generic-procedure 2 'bar))
          
          (define foo-baz (make-generic-procedure '(1 . 2) 'foo-baz))
          
          (define foo-mum (make-generic-procedure '(1 . #f)))
— procedure: generic-procedure? object

Returns ‘#t’ if object is a generic procedure, and ‘#f’ otherwise.

— procedure: guarantee-generic-procedure object caller

Signals an error if object is not a generic procedure. Caller is a symbol that is printed as part of the error message and is intended to be the name of the procedure where the error occurs.

— procedure: generic-procedure-arity generic

Returns the arity of generic, as given to make-generic-procedure.

— procedure: generic-procedure-name generic

Returns the name of generic, as given to make-generic-procedure.

— procedure: generic-procedure-applicable? generic operands

Returns ‘#t’ if generic is applicable to operands (which must be a list of objects), and ‘#f’ otherwise.

— condition type: condition-type:no-applicable-methods operator operands

This condition type is signalled when a generic procedure is applied and there are no applicable methods for the given operands. The condition's operator field contains the generic procedure and the operands field contains the given operands.

— condition type: condition-type:extra-applicable-methods operator operands

This condition type is signalled when a generic procedure is applied and there are more than one applicable methods for the given operands. The condition's operator field contains the generic procedure and the operands field contains the given operands.