Skip to content

Instantly share code, notes, and snippets.

@wynemo
Created October 16, 2012 15:54
Show Gist options
  • Select an option

  • Save wynemo/3900132 to your computer and use it in GitHub Desktop.

Select an option

Save wynemo/3900132 to your computer and use it in GitHub Desktop.
scheme learning
$ 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)
(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