-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathall_defs.exh
13 lines (13 loc) · 1.21 KB
/
all_defs.exh
1
2
3
4
5
6
7
8
9
10
11
12
13
add: ((number number) number (define add (lambda (a b) (if a (add (pred a) (succ b)) b))))
mul: ((number number) number (define mul (lambda (a b) (if a (add (mul (pred a) b) b) 0))))
logical_not: ((number) number (define logical_not (lambda (a) (if a 0 (succ a)))))
logical_or: ((number number) number (define logical_or (lambda (a b) (if a a b))))
logical_and: ((number number) number (define logical_and (lambda (a b) (if a b 0))))
logical_nand: ((number number) number (define logical_nand (lambda (a b) (logical_not (logical_and b a)))))
logical_xor: ((number number) number (define logical_xor (lambda (a b) (if a (logical_not b) b))))
logical_parity: ((list) number (define logical_parity (lambda (l) (if l (logical_xor (logical_parity (cdr l)) (car l)) 0))))
index: ((list number) S-expression (define index (lambda (l a) (if a (index (cdr l) (pred a)) (car l)))))
length: ((list) number (define length (lambda (l) (if l (succ (length (cdr l))) 0))))
sum: ((list) number (define sum (lambda (l) (if l (add (sum (cdr l)) (car l)) 0))))
power: ((number number) number (define power (lambda (a b) (if b (mul (power a (pred b)) a) 1))))
factorial: ((number) number (define factorial (lambda (n) (if n (mul (factorial (pred n)) n) 1))))