A simple example to show essential scheme syntax.
(define (abs x) (if (< x 0) (- x) x)) (define (square x) (* x x)) (define (average x y) (/ (+ x y) 2)) (define (sqrt x) (define (improve guess) (average guess (/ x guess))) (define (good-enough? guess) (< (abs (- (square guess) x)) 0.001)) (define (try guess) (if (good-enough? guess) guess (try (improve guess)))) (try 1))
Write Good Code Last time we have the codes for calculating square root. {% highlight scheme %} (define (abs x) (if (< x 0) (- x) x)) (define (square x) (* x x)) (define (aver...
Write Good Code The idea of extracting functions needs practice. Here is another example. It multiply each elements in the list by n. 1 2 3 4 5 6 7 (define (scale-list n l) (if (null? l) ...
currently working on lab07 CS61A Week 6 objects have attributes today.year and method today.strftime(...) objects with good design will do what it supposed to do str(tmr - today) objects c...
Bandwidth Estimation for Circuits
SICP Lecture 02A
A new version of content is available.