You are looking at historical revision 15435 of this page. It may differ significantly from its current revision.
This extension provides a simple abstraction for defining abstract interfaces with separate implementations.
[syntax] (interface NAME DEFINITION ...)
Declares NAME to be an interface that provides the definitions DEFINITION .... DEFINITION should be a value definition of the form
(define NAME [VALUE])
(define (NAME VAR ...) [BODY ...])
The values and bodies of the given definitions are optional and default to (void) (for value definitions) or a procedure that signals a runtime error (for procedure definitions). If a value/body is given, it provides a default for later implementations of this interface (see below).
[syntax] (implementation NAME DEFINITION ...)
Defines an implementation of interface NAME. An implementation is a record structure holding the given definitions. Note that implementation returns a first-class object, in contrast to interface which is a declaration.
Each definition declared in the interface can be accessed by invoking the definition-name with an implementation as its sole argument.
<scheme> (interface counter
(define (counter-new)) (define (counter-inc c)) (define (counter-get c)))
(implementation counter (define (counter-new) 0) (define counter-inc add1) (define counter-get identity)))
(let ((c1 ((counter-new simple-counter))))
(print ((counter-get simple-counter) c1)) ; ==> "0" (let ((c2 ((counter-inc simple-counter) c1))) (print ((counter-get simple-counter) c2)))) ; ==> "1"
(implementation counter (define (counter-inc c) (let ((c2 (add1 c))) (print "increasing counter " c " to " c2 "! is this cool or what?") c2))))
Copyright (c) 2009, The CHICKEN Team All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- Initial release