summaryrefslogtreecommitdiffstats
path: root/ps04_combinators_amb/repl.scm
blob: b8ff8b78f4a534ff7bf113f17c5967a40470e3be (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
(declare (usual-integrations write write-line pp eval))

(define write
  (make-generic-operator 1
    (access write user-initial-environment)))

(define write-line
  (make-generic-operator 1
    (access write-line user-initial-environment)))

(define pp
  (make-generic-operator 1
    (access pp user-initial-environment)))

(define (procedure-printable-representation procedure)
  `(compound-procedure
    ,(procedure-parameters procedure)
    ,(procedure-body procedure)
    <procedure-environment>))

(defhandler write
  (compose write procedure-printable-representation)
  compound-procedure?)

(defhandler write-line
  (compose write-line procedure-printable-representation)
  compound-procedure?)

(defhandler pp
  (compose pp procedure-printable-representation)
  compound-procedure?)

 
(define (read) (prompt-for-command-expression "eval> "))

(define the-global-environment)

(define (init)
  (set! the-global-environment
	(extend-environment '() '() the-empty-environment))
  (repl))

(define (repl)
  (let ((input (read)))
    (write-line (eval input the-global-environment))
    (repl)))

(define go repl)