On this page:
make-overloads
overloads?
overloads-default-signature
set-method
remove-method
prefer-method
unprefer-method
exn: fail: multimethod
find-methods
Version: 4.1.4.1

2 Sets of Overloaded Methods

 (require (planet "overloads.ss" ("murphy" "multimethod.plt" 2 1)))

This module provides procedures to manage sets of overloaded methods. It’s the backend doing all the work behind multimethods.

(make-overloads [#:default default-signature    
  #:hierarchy ref-hierarchy])  overloads?
  default-signature : any/c = #f
  ref-hierarchy : (-> hierarchy?) = global-hierarchy

Creates a new overload set. default-signature is a default signature that is looked up in the method tables if the one passed to find-methods doesn’t match any implementation. ref-hierarchy is a procedure yielding the value hierarchy to be used by signature comparisons, it defaults to global-hierarchy, ie. the default behaviour is to read the current value of the global hierarchy parameter every time the hierarchy is needed.

(overloads? v)  boolean?
  v : any/c

Checks whether the given object is an overload set.

(overloads-default-signature m)  any/c
  m : overloads?

Retrieves the default signature of an overload set.

(set-method os signature method)  overloads?
  os : overloads?
  signature : any/c
  method : procedure?

Takes the overloads os and transforms them into new overloads that map the given signature to the method implementation method.

Any existing mapping for the given signature is replaced.

(remove-method os signature)  overloads?
  os : overloads?
  signature : any/c

Takes the overloads os and transforms them into new overloads that have no direct mapping for the given signature to any method implementation.

(prefer-method os signature-a signature-b)  overloads?
  os : overloads?
  signature-a : any/c
  signature-b : any/c

Takes the overloads os and transforms them into new overloads that prefer dispatching via signature-a over dispatching via signature-b.

(unprefer-method os signature-a signature-b)  overloads?
  os : overloads?
  signature-a : any/c
  signature-b : any/c

Takes the overloads os and transforms them into new overloads that do not prefer dispatching via signature-a over dispatching via signature-b.

(struct (exn:fail:multimethod exn:fail) (overloads signature))
  overloads : overloads?
  signature : any/c

An exception raised to signal a problem with multimethod dispatch. find-methods raises it to indicate that the overloads contain no matching method for signature.

(find-methods os signature)  (listof procedure?)
  os : overloads?
  signature : any/c

Retrieves all method implementations from overloads os that match the given signature and that can be strictly ordered by specificity or preference.

The method lookup works as follows: