-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.scm
51 lines (42 loc) · 1.24 KB
/
base.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(define (tail-recursive-sum acc vals)
(if (null? vals)
acc
(tail-recursive-sum
(binary-sum acc (car vals))
(cdr vals))))
(define (+ . vals)
(tail-recursive-sum 0 vals))
(define (tail-recursive-subtract acc vals)
(if (null? vals)
acc
(tail-recursive-subtract
(binary-subtract acc (car vals))
(cdr vals))))
(define (- . vals)
(if (null? vals)
0 ;should raise an error, but I don't have them yet
(if (null? (cdr vals))
(binary-subtract 0 (car vals))
(tail-recursive-subtract (car vals) (cdr vals)))))
(define (tail-recursive-multiply acc vals)
(if (null? vals)
acc
(tail-recursive-multiply
(binary-multiply acc (car vals))
(cdr vals))))
(define (* . vals)
(tail-recursive-multiply 1 vals))
(define (tail-recursive-divide acc vals)
(if (null? vals)
acc
(tail-recursive-divide
(binary-divide acc (car vals))
(cdr vals))))
(define (/ . vals)
(if (null? vals)
0 ;should raise an error, but I don't have them yet
(if (null? (cdr vals))
(binary-divide 1 (car vals))
(tail-recursive-divide (car vals) (cdr vals)))))
(define call/cc call-with-current-continuation)
; vim: expandtab tabstop=2