#### 12.6.2 Method Generators

Generic-procedure methods are dynamically chosen by generators, which are procedures of two arguments. Each generic procedure has a set of associated generators. Whenever the procedure is applied, each associated generator is applied to two arguments: the generic procedure and a list of the dispatch tags for the operands. The return value from the generator is either a method (a procedure accepting that number of arguments) or ‘`#f`’. In order for the application to succeed, exactly one of the generic procedure’s generators must return a method.

Once a method has been chosen, it is cached. A subsequent call to the generic procedure with operands of the same types will reuse that cached method. Consequently, it is important that generators be functional: they must always compute the same value from the same arguments.

procedure: add-generic-procedure-generator generic generator

  Adds generator to generic’s set of generators and returns an unspecified value.

procedure: remove-generic-procedure-generator generic generator

  Removes generator from generic’s set of generators and returns an unspecified value.

procedure: remove-generic-procedure-generators generic tags

  Calls each of generic’s set of generators on tags and removes each generator that returns a method. Returns an unspecified value.

procedure: generic-procedure-generator-list generic

  Returns a list of generic’s generators.

As a convenience, each generic procedure can have a default generator, which is called only when all of the other generators have returned ‘`#f`’. When created, a generic procedure has no default generator.

procedure: generic-procedure-default-generator generic

  Returns generic’s default generator.

procedure: set-generic-procedure-default-generator! generic generator

  Sets generic’s default generator to generator and returns an unspecified value.