(type egg)
(signature "interfaces egg")
(timestamp 1612269487)
(sxml ((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/interfaces" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (toc) (tags "eggs")) (section 2 "interfaces" (p "This extension provides a simple abstraction for defining abstract interfaces with separate implementations.") (section 3 "Documentation" (section 4 "interface" (def (sig (syntax "(interface NAME DEFINITION ...)" (id interface))) (p "Declares " (tt "NAME") " to be an " (i "interface") " that provides the definitions " (tt "DEFINITION ...") ". " (tt "DEFINITION") " should be a value definition of the form") (pre " (define NAME [VALUE])") (p "or") (pre " (define (NAME VAR ...) [BODY ...])") (p "The values and bodies of the given definitions are optional and default to " (tt "(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)."))) (section 4 "implementation" (def (sig (syntax "(implementation NAME DEFINITION ...)" (id implementation))) (p "Defines an " (i "implementation") " of interface " (tt "NAME") ". An implementation is a record structure holding the given definitions. Note that " (tt "implementation") " returns a first-class object, in contrast to " (tt "interface") " which is a declaration.") (p "Each definition declared in the interface can be accessed by invoking the definition-name with an implementation as its sole argument.")))) (section 3 "Example" (highlight scheme "(interface counter\n  (define (counter-new))\n  (define (counter-inc c))\n  (define (counter-get c)))\n\n(define simple-counter\n  (implementation\n    counter\n    (define (counter-new) 0)\n    (define counter-inc add1)\n    (define counter-get identity)))\n\n(let ((c1 ((counter-new simple-counter))))\n  (print ((counter-get simple-counter) c1))     ; ==> \"0\"\n  (let ((c2 ((counter-inc simple-counter) c1)))\n    (print ((counter-get simple-counter) c2)))) ; ==> \"1\"\n\n(define logged-counter\n  (implementation\n    counter\n    (define (counter-inc c)\n      (let ((c2 (add1 c)))\n        (print \"increasing counter \" c \" to \" c2 \"! is this cool or what?\")\n        c2))))")) (section 3 "Requirements" (p (int-link "records")))) (section 2 "Author" (p (int-link "/users/felix winkelmann" "felix winkelmann"))) (section 2 "License" (p "This code is in the public domain")) (section 2 "Version History" (dl (dt "0.3") (dd "fixed bug related to implementation constructors exported from modules") (dt "0.2") (dd "added missing dependency") (dt "0.1") (dd "Initial release")))))
