Created
October 16, 2012 15:54
-
-
Save wynemo/3900132 to your computer and use it in GitHub Desktop.
scheme learning
This file contains hidden or 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
| $ sudo aptitude install guile-1.8 | |
| $ guile | |
| (trace function-name) | |
| Then, whenever this function is called, it will print a message to the screen showing what arguments it was called with. When the procedure returns, it will print a message showing what value that call returned. | |
| To turn off tracing, use the command: | |
| (untrace function-name) | |
| Or, to turn off all tracing, simply: | |
| (untrace) |
This file contains hidden or 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
| (define (new-if p tc ec) (cond (p tc) (else ec))) | |
| (define (square x) (* x x)) | |
| (define (sqrt-iter guess x) | |
| (new-if (good-enough? guess x) | |
| guess | |
| (sqrt-iter (improve guess x) | |
| x))) | |
| (define (improve guess x) | |
| (average guess (/ x guess))) | |
| (define (average x y) | |
| (/ (+ x y) 2)) | |
| (define (good-enough? guess x) | |
| (< (abs (- (square guess) x)) 0.001)) | |
| (define (sqrt x) | |
| (sqrt-iter 1.0 x)) | |
| (trace sqrt-iter) | |
| (trace improve) | |
| (trace good-enough?) | |
| (sqrt 9) | |
| (new-if ( > 5 1) 6 x) | |
| (if (> 5 1) 6 x) | |
| (cond ((> 5 1) 6) (else x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment