scheme learning
(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))
$ 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)