summaryrefslogtreecommitdiffstats
path: root/cpp/sca/test/store-script/store-script.scm
blob: 8af88b45f006a9e6879a089eba4929ca1d504f91 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(display "Currency implementation")

(define (currency_convert from to amount) 
  (if (equal? to "EUR") (* amount 0.70) amount)
)

(define (currency_symbol currency) 
  (if (equal? currency "EUR") "E" "$")
)

(define (currency_impl op args)
  (cond
    ((equal? op "convert") (apply currency_convert args))
    ((equal? op "symbol") (apply currency_symbol args))
  )
)

(display "Currency composite")

(define (currency_service op . args) (currency_impl op args))

(display "Catalog implementation")

(define (catalog_get converter)
  (define (convert price) (converter "convert" "USD" "USD" price))

  (define code "USD")
  (define symbol (converter "symbol" code))

  (list (list "apple" code symbol (convert 2.99))
    (list "orange" code symbol (convert 3.55))
    (list "pear" code symbol (convert 1.55))
   )
)

(define (catalog_impl converter op args)
  (cond
    ((equal? op "get") (apply catalog_get (cons converter args)))
  )
)

(display "Catalog composite")

(define (catalog_service op . args) (catalog_impl currency_service op args))

(display "Cart implementation")

(define (cart_post content item)
  (cons item content)
)

(define (cart_getall content)
  content
)

(define (cart_impl op args)
  (cond
    ((equal? op "post") (apply cart_post args))
    ((equal? op "getall") (apply cart_getall args))
  )
)

(display "Store UI implementation")

(define (storeui_post cart content item)
  (cart "post" content item)
)

(define (storeui_getcart cart content)
  (cart "getall" content)
)

(define (storeui_getcatalog catalog)
  (catalog "get")
)

(define (storeui_impl cart catalog op args)
  (cond
    ((equal? op "post") (apply storeui_post (cons cart args)))
    ((equal? op "getall") (apply storeui_getcart (cons cart args)))
    ((equal? op "getcatalog") (apply storeui_getcatalog (cons catalog args)))
  )
)

(display "Store UI composite")

(define (cart_service op . args) (cart_impl op args))

(define (storeui_service op . args) (storeui_impl cart_service catalog_service op args))

(display "Store UI test case")

(define catalog (storeui_service "getcatalog"))
(define empty (list))
(define apple (car catalog))
(define full (storeui_service "post" empty apple))
(display (storeui_service "getall" full))