public
Description: An easy way to make web apps (in PLT Scheme)
Homepage: http://blog.leftparen.com
Clone URL: git://github.com/vegashacker/leftparen.git
Click here to lend your support to: leftparen and make a donation at www.pledgie.com !
leftparen / layering-example.scm
100644 42 lines (28 sloc) 0.822 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#lang scheme/base
 
(require scheme/unit)
 
(provide foo bar)
 
;; we want to be able to extend and have original library calls be able to call the
;; extended version.
 
;; the trick is to use a recursive unit. very cool.
 
(define-signature my-sig^ (foo bar))
 
(define-unit base-unit%
  (import (prefix from-future: my-sig^))
  (export my-sig^)
 
  (define (foo)
    (list "foo base" (from-future:bar)))
 
  (define (bar)
    "bar base")
  )
 
(define-unit extension-unit%
  (import (prefix base: my-sig^))
  (export my-sig^)
 
  (define foo base:foo)
 
  (define (bar)
    "bar extension")
  )
 
(define-compound-unit merged-unit%
  (import)
  (export RESULT)
  (link [((BASE : my-sig^)) base-unit% RESULT]
        [((RESULT : my-sig^)) extension-unit% BASE]))
 
(define-values/invoke-unit merged-unit% (import) (export my-sig^))