source: project/wiki/eggref/4/interfaces @ 15489

Last change on this file since 15489 was 15489, checked in by felix winkelmann, 10 years ago

updated version

File size: 3.5 KB
Line 
1[[toc:]]
2[[tags: eggs]]
3
4== interfaces
5
6This extension provides a simple abstraction for defining abstract interfaces
7with separate implementations.
8
9=== Documentation
10
11==== interface
12
13  [syntax] (interface NAME DEFINITION ...)
14
15Declares {{NAME}} to be an ''interface'' that provides the definitions
16{{DEFINITION ...}}. {{DEFINITION}} should be a value definition of
17the form
18
19  (define NAME [VALUE])
20
21or
22
23  (define (NAME VAR ...) [BODY ...])
24
25The values and bodies of the given definitions are optional and default
26to {{(void)}} (for value definitions) or a procedure that signals a
27runtime error (for procedure definitions). If a value/body is given,
28it provides a default for later implementations of this interface
29(see below).
30
31
32==== implementation
33
34  [syntax] (implementation NAME DEFINITION ...)
35
36Defines an ''implementation'' of interface {{NAME}}. An implementation is
37a record structure holding the given definitions. Note that {{implementation}}
38returns a first-class object, in contrast to {{interface}} which is a declaration.
39
40Each definition declared in the interface can be accessed by invoking the
41definition-name with an implementation as its sole argument.
42
43
44=== Example
45
46<enscript hilight=scheme>
47(interface counter
48  (define (counter-new))
49  (define (counter-inc c))
50  (define (counter-get c)))
51
52(define simple-counter
53  (implementation
54    counter
55    (define (counter-new) 0)
56    (define counter-inc add1)
57    (define counter-get identity)))
58
59(let ((c1 ((counter-new simple-counter))))
60  (print ((counter-get simple-counter) c1))     ; ==> "0"
61  (let ((c2 ((counter-inc simple-counter) c1)))
62    (print ((counter-get simple-counter) c2)))) ; ==> "1"
63
64(define logged-counter
65  (implementation
66    counter
67    (define (counter-inc c)
68      (let ((c2 (add1 c)))
69        (print "increasing counter " c " to " c2 "! is this cool or what?")
70        c2))))
71</enscript>
72
73
74=== Requirements
75
76[[/eggref/4/records]]
77
78== Author
79
80[[/users/felix winkelmann|felix winkelmann]]
81
82== License
83
84 Copyright (c) 2009, The CHICKEN Team
85 All rights reserved.
86
87 Redistribution and use in source and binary forms, with or without
88 modification, are permitted provided that the following conditions are met:
89 
90   Redistributions of source code must retain the above copyright notice,
91     this list of conditions and the following disclaimer.
92   Redistributions in binary form must reproduce the above copyright notice,
93     this list of conditions and the following disclaimer in the
94     documentation and/or other materials provided with the distribution.
95   Neither the name of the author nor the names of its contributors may be
96     used to endorse or promote products derived from this software without
97     specific prior written permission.
98 
99 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
100 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
102 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
103 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
104 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
105 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
106 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
107 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
108 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
109 POSSIBILITY OF SUCH DAMAGE.
110
111== Version History
112
113; 0.2 : added missing dependency
114; 0.1 : Initial release
Note: See TracBrowser for help on using the repository browser.