Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

  1. Outdated egg!
  2. interfaces
    1. Documentation
      1. interface
      2. implementation
    2. Example
    3. Requirements
  3. Author
  4. License
  5. Version History

interfaces

This extension provides a simple abstraction for defining abstract interfaces with separate implementations.

Documentation

interface

[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])

or

 (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).

implementation

[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.

Example

(interface counter
  (define (counter-new))
  (define (counter-inc c))
  (define (counter-get c)))

(define simple-counter
  (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"

(define logged-counter
  (implementation
    counter
    (define (counter-inc c)
      (let ((c2 (add1 c)))
        (print "increasing counter " c " to " c2 "! is this cool or what?")
        c2))))

Requirements

records

Author

felix winkelmann

License

This code is in the public domain

Version History

0.3
fixed bug related to implementation constructors exported from modules
0.2
added missing dependency
0.1
Initial release