-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-4.23.scm
76 lines (64 loc) · 1.87 KB
/
ex-4.23.scm
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
;; original
(define (analyze-sequence exps)
(define (sequentially proc1 proc2)
(lambda (env) (proc1 env) (proc2 env)))
(define (loop first-proc rest-procs)
(if (null? rest-procs)
first-proc
(loop (sequentially first-proc (car rest-procs))
(cdr rest-procs))))
(let ((procs (map analyze exps)))
(if (null? procs)
(error "Empty sequence -- ANALYZE"))
(loop (car procs) (cdr procs))))
;; Alyssa ver
(define (analyze-sequence exps)
(define (execute-sequence procs env)
(cond ((null? (cdr procs)) ((car procs) env))
(else ((car procs) env)
(execute-sequence (cdr procs) env))))
(let ((procs (map analyze exps)))
(if (null? procs)
(error "Empty sequence -- ANALYZE"))
(lambda (env) (execute-sequence procs env))))
;; exps1
(define orig1
(lambda (env) ...))
;; exps2
(define orig2
(lambda (env)
((lambda (env) ...) env)
((lambda (env) ...) env)))
;; exps3
(define orig3
(lambda (env)
((lambda (env)
((lambda (env) ...) env)
((lambda (env) ...) env))
env)
((lambda (env) ...)
env)))
(define alyssa1
(lambda (env)
((lambda (env) ...) env)))
;; (lambda (env) (execute-sequence procs env))))
(define alyssa2
(lambda (env)
((lambda (env) ...) env)
((lambda (env) ...) env)))
;; (lambda (env) (execute-sequence procs env))))
(define alyssa3
(lambda (env)
((lambda (env) ...) env)
((lambda (env) ...) env)
((lambda (env) ...) env)))
;; (lambda (env) (execute-sequence procs env))))
;; Alyssaの版は並びそのものの解析を行っていない。Alyssaの版は実行時に条件判定やループを実行することになりorignalの版より非効率的な実装である。
(define (main args)
(print (orig1 3))
(print (orig2 3))
(print (orig3 3))
(print (alyssa1 3))
(print (alyssa2 3))
(print (alyssa3 3))
)