Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 22 lines (15 sloc) 0.427 kb
7ce90b3 Lazy lists library
Andrey Paramonov authored
1 (load "lazy")
2
3 ; Square root by Newton's method
4 ; > (mysqrt 1 0.001 4.0)
5 ; > (mysqrt 1 0.001 200.0)
6
7 (defun repeat (f a)
8 (lazy-cons a (repeat f (funcall f a))))
9
10 (defun next (n)
11 (lambda (x) (/ (+ x (/ n x)) 2)))
12
13 (defun within (eps lst)
14 (if (<= (abs (- (lazy-car lst) (lazy-cadr lst))) eps)
15 (lazy-cadr lst)
16 (within eps (lazy-cdr lst))))
17
18 (defun mysqrt (a eps n)
19 (within eps
20 (repeat (next n) a)))
21
Something went wrong with that request. Please try again.