source: project/wiki/eggref/5/chibi-generic @ 37367

Last change on this file since 37367 was 37367, checked in by Diego, 3 years ago

Fix link

File size: 1.1 KB
Line 
1[[tags: egg]]
2
3[[toc:]]
4
5== chibi-generic
6
7Chibi Scheme's simple generic function interface
8
9Original page here: [[http://synthcode.com/scheme/chibi/lib/chibi/generic.html]]
10
11=== Usage
12
13<syntax>(define-generic name)</syntax>
14
15Define a new generic function named {{name}}.
16
17<syntax>(define-method (name params ...) body ...)</syntax>
18
19Each parameter in {{params}} should be either a single identifier or a list of the
20form {{(param type)}} where {{param}} is the parameter name and {{type}} is a
21predicate which returns true if it's argument is of the correct type.
22Parameters without a predicate will always match. If multiple methods
23satisfy the arguments, the most recent method will be used. The special
24form {{(call-next-method)}} can be invoked to call the next most recent
25method with the same arguments.
26
27<procedure>(make-generic name)</procedure>
28
29Create a new first-class generic function named {{name}}.
30
31<procedure>(generic-add! g preds f)</procedure>
32
33Extend the generic {{g}} with a new method {{f}} that applies when all parameters
34match the given list of predicates {{preds}}.
35
Note: See TracBrowser for help on using the repository browser.