-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0755b59
commit 59241b6
Showing
170 changed files
with
11,051 additions
and
30 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,18 @@ | ||
(load "354.scm") | ||
(load "370.scm") | ||
(load "ch351.scm") | ||
|
||
(define (square x) (* x x)) | ||
(define (sum-square x) ( (square (car x)) (square (cadr x)))) | ||
(define (squaresn s) | ||
(define (stream-cadr s) (stream-car (stream-cdr s))) | ||
(define (stream-caddr s) (stream-cadr (stream-cdr s))) | ||
(let ((scar (stream-car s)) | ||
(scadr (stream-cadr s)) | ||
(scaddr (stream-caddr s))) | ||
(if (= (sum-square scar) (sum-square scadr) (sum-square scaddr)) | ||
(cons-stream (list (sum-square scar) scar scadr scaddr) | ||
(squaresn (stream-cdr (stream-cdr (stream-cdr s))))) | ||
(squaresn (stream-cdr s))))) | ||
(define square-numbers | ||
(squaresn (weighted-pairs integers integers sum-square))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,13 @@ | ||
(define (list-of-values exps env) | ||
(if (no-operands? exps) | ||
'() | ||
(let ((first (eval (first-operand exps) env))) | ||
(cons first | ||
(list-of-values (rest-operands exps) env))))) | ||
|
||
(define (list-of-values exps env) | ||
(if (no-operands? exps) | ||
'() | ||
(let ((rest (list-of-values (rest-operands exps) env))) | ||
(cons (eval (first-operand exps) env) | ||
rest)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,7 @@ | ||
(define (make-frame variables values) | ||
(map cons variables values)) | ||
(define (frame-variables frame) (map car frame)) | ||
(define (frame-values frame) (map cdr frame)) | ||
(define (add-binding-to-frame! var val frame) | ||
(cons (cons var val) | ||
frame)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,32 @@ | ||
(define (lookup-variable-in-environment var env) | ||
(if (eq? env the-empty-environment) | ||
false | ||
(let ((result (lookup-variable-in-frame var (first-frame env)))) | ||
(if (true? result) | ||
result | ||
(lookup-variable-in-frame var (enclosing-environment env)))))) | ||
|
||
(define (lookup-variable-in-frame var frame) | ||
(define (scan-in-frame vars vals) | ||
(cond ((null? vars) false) | ||
((eq? var (car vars)) vals) | ||
(else (scan-in-frame (cdr vars) (cdr vals))))) | ||
(scan-in-frame (frame-variables frame) (frame-values frame))) | ||
|
||
(define (lookup-variable-value var env) | ||
(let ((pos (lookup-variable-in-environment var env))) | ||
(if pos | ||
(car pos) | ||
(error "Unbound variable" var)))) | ||
(define (set-variable-value! var val env) | ||
(let ((pos (lookup-variable-in-environment var env))) | ||
(if pos | ||
(set-car! vals val) | ||
(error "Unbound variable --SET!" var)))) | ||
|
||
(define (define-variable! var val env) | ||
(let ((first (first-frame env)) | ||
(pos (lookup-variable-in-frame var first))) | ||
(if pos | ||
(set-car! vals val) | ||
(add-binding-to-frame! var val first)))) |
Oops, something went wrong.