12 | 12 |
; If you're interested, you can look at earlier revisions of this
|
13 | 13 |
; file in the repository -- but you are probably not that interested.
|
14 | 14 |
|
15 | |
; Load an S-expression from a named file.
|
16 | |
(define load-sexp
|
17 | |
(lambda (filename)
|
18 | |
(with-input-from-file filename (lambda () (read)))))
|
19 | |
|
20 | 15 |
; The pseudocode is:
|
21 | 16 |
;
|
22 | |
; pop the last file off the command line
|
23 | |
; load the sexp from it -> current sexp
|
24 | |
; while there are files remaining on the command line:
|
25 | |
; pop the last file off the command line
|
|
17 |
; pop the top sexp off the tower -> current sexp
|
|
18 |
; while there are sexps remaining on the tower:
|
|
19 |
; pop the top sexp off the tower
|
26 | 20 |
; wrap the current sexp with it as an interpreter -> current sexp
|
27 | 21 |
; evaluate current sexp as Scheme
|
28 | 22 |
|
|
33 | 27 |
(interpret sexp))))
|
34 | 28 |
|
35 | 29 |
(define tower-rec
|
36 | |
(lambda (filenames sexp)
|
37 | |
(if (null? filenames)
|
|
30 |
(lambda (sexp-tower sexp)
|
|
31 |
(if (null? sexp-tower)
|
38 | 32 |
(eval sexp (scheme-report-environment 5))
|
39 | |
(let* ((filename (car filenames))
|
40 | |
(rest (cdr filenames))
|
41 | |
(sexp (wrap-sexp sexp (load-sexp filename))))
|
42 | |
(tower-rec rest sexp)))))
|
43 | |
|
|
33 |
(let* ((interpreter-sexp (car sexp-tower))
|
|
34 |
(rest (cdr sexp-tower)))
|
|
35 |
(tower-rec rest (wrap-sexp sexp interpreter-sexp))))))
|
|
36 |
|
44 | 37 |
(define tower
|
45 | |
(lambda (filenames)
|
46 | |
(let* ((filenames (reverse filenames)))
|
47 | |
(if (null? filenames)
|
|
38 |
(lambda (sexp-tower)
|
|
39 |
(let* ((sexp-tower (reverse sexp-tower)))
|
|
40 |
(if (null? sexp-tower)
|
48 | 41 |
'()
|
49 | |
(let* ((filename (car filenames))
|
50 | |
(rest (cdr filenames))
|
51 | |
(sexp (load-sexp filename)))
|
|
42 |
(let* ((sexp (car sexp-tower))
|
|
43 |
(rest (cdr sexp-tower)))
|
52 | 44 |
(tower-rec rest sexp))))))
|