Cleanup pass over comments in chapter 1.

This commit is contained in:
Elf M. Sternberg 2015-04-15 16:01:30 -07:00
parent 5ac7969712
commit 525668310b
1 changed files with 12 additions and 19 deletions

View File

@ -26,7 +26,7 @@
(define env_global env_init) (define env_global env_init)
; So, this macro places *into the current scope* (i.e. no building of ; So, this macro places *into the current scope* (i.e. no building of
; a new scope that get's reaped upon exit) the names of variables and ; a new scope that gets reaped upon exit) the names of variables and
; potential initial values. ; potential initial values.
(define-syntax definitial (define-syntax definitial
@ -49,6 +49,9 @@
(apply value values) (apply value values)
(wrong-syntax #'here "Incorrect arity ~s" (list 'name values)))))))) (wrong-syntax #'here "Incorrect arity ~s" (list 'name values))))))))
; Sometimes, you do have to define something before you use it. Lesson
; learned.
(define the-false-value (cons "false" "boolean")) (define the-false-value (cons "false" "boolean"))
(definitial t #t) (definitial t #t)
@ -68,9 +71,9 @@
; This function extends the environment so that *at this moment of ; This function extends the environment so that *at this moment of
; extension* the conslist head points to the old environment, then ; extension* the conslist head points to the old environment, then
; when it's done it points to the new environment. What's really ; when it's done it points to the new environment. What's interesting
; interesting is that the conslist head points to the last object ; is that the conslist head points to the last object initialized, not
; initialized, not the first. ; the first.
(define (extend env variables values) (define (extend env variables values)
(cond ((pair? variables) (cond ((pair? variables)
@ -84,12 +87,9 @@
(wrong-syntax #'here "Too many values"))) (wrong-syntax #'here "Too many values")))
((symbol? variables) (mcons (mcons variables values) env)))) ((symbol? variables) (mcons (mcons variables values) env))))
; This is interesting. Already we're starting to get some scope here. ; Already we're starting to get some scope here. Note that
; Note that make function provides the environment, not the invoke. ; make-function provides the environment, not the invoke. This makes
; But we're still only passing the empty init environment. ; this a lexically scoped interpreter.
; Now a different order, one in which closures aren't present, makes
; the code fragile. So:
(define (make-function variables body env) (define (make-function variables body env)
(lambda (values) (lambda (values)
@ -102,12 +102,6 @@
(fn args) (fn args)
(wrong-syntax #'here "Not an function ~s" fn))) (wrong-syntax #'here "Not an function ~s" fn)))
; The text points out that the global environment is being
; pushed/popped as needed and rebuilt with every function call. In
; this case, the defining envirnoment is no longer being used at all,
; only the current one. This would make this a dynamically scope
; language, no?
; Iterate through the exps, return the value of the last one. ; Iterate through the exps, return the value of the last one.
(define (eprogn exps env) (define (eprogn exps env)
@ -133,8 +127,7 @@
(define-syntax mcadr (syntax-rules () ((_ e) (mcdr (mcar e))))) (define-syntax mcadr (syntax-rules () ((_ e) (mcdr (mcar e)))))
; Iterate through the environment, find an ID, return its associated ; Iterate through the environment, find an ID, return its associated
; value. This is a completely global, resettable environment; we're ; value.
; talking BASIC here.
(define (lookup id env) (define (lookup id env)
(if (mpair? env) (if (mpair? env)
@ -154,7 +147,7 @@
(update! id (mcdr env) value)) (update! id (mcdr env) value))
(wrong-syntax #'here "No such binding ~s" id))) (wrong-syntax #'here "No such binding ~s" id)))
; Different evaluation rules. ; Core evaluation rules.
(define (evaluate exp env) (define (evaluate exp env)
(if (atom? exp) (if (atom? exp)