#lang scribble/doc @(require scribble/manual scribble/eval (for-label scheme "../main.ss")) @title{Multimethods} @table-of-contents[] @defmodule[(planet "main.ss" ("murphy" "multimethod.plt" 1 1))]{ Provides procedures with versatile dispatch on any number of their arguments. Inheritance hierarchies for method signatures can be defined in an ad-hoc fashion or class and interface hierarchies from @schememodname[scheme/class] can be used. } A small usage example: @defs+int[ #:eval (let ([sandbox (make-base-eval)]) (sandbox '(require "main.ss")) sandbox) ( (derive 'rock 'item) (derive 'paper 'item) (derive 'scissors 'item) (define-multi (beats? a b) :: (vector-immutable a b)) (define-method (beats? a b) :: #(item item) #f) (define-method (beats? a b) :: #(rock scissors) #t) (define-method (beats? a b) :: #(paper rock) #t) (define-method (beats? a b) :: #(scissors paper) #t) ) (derived? 'rock 'item) (derived? 'rock 'rock) (derived? 'rock 'paper) (descendants 'item) (beats? 'rock 'paper) (beats? 'rock 'scissors) (beats? 'limestone 'scissors) (derive 'limestone 'rock) (beats? 'limestone 'scissors) (parameterize-multi (beats?) (define-method (beats? a b) :: #(limestone paper) #t) (beats? 'limestone 'paper)) (beats? 'limestone 'paper) (parameterize ([global-hierarchy (derive (global-hierarchy) 'marble 'rock)]) (beats? 'marble 'scissors)) (beats? 'marble 'scissors) ] @include-section["hierarchy.scrbl"] @include-section["multimethod.scrbl"] @section{License} Copyright (c) 2009 by @link["mailto:chust@web.de"]{Thomas Chust @""}. This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You can find a copy of the GNU Lesser General Public License at @link["http://www.gnu.org/licenses/lgpl-3.0.html"]{http://www.gnu.org/licenses/lgpl-3.0.html}.