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

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

Add chibi-generic wiki page

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