aboutsummaryrefslogtreecommitdiff
path: root/src/lisp
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-04-10 13:08:46 +0100
committerAkshay <[email protected]>2021-04-10 13:08:46 +0100
commit8d5fecc23f4e986c74295c58473c6ea8d840d955 (patch)
treef9bea6b4bb21b74ee18bb1b679ec0ee959f9b716 /src/lisp
parenteab6c543d19f7546f1151cca32663035006af702 (diff)
introduce modulus arithmetic to std lisp
Diffstat (limited to 'src/lisp')
-rw-r--r--src/lisp/std.lisp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lisp/std.lisp b/src/lisp/std.lisp
index 2a042a0..6c5beed 100644
--- a/src/lisp/std.lisp
+++ b/src/lisp/std.lisp
@@ -9,6 +9,18 @@
9(define (cdddddr ls) (cdr (cddddr ls))) 9(define (cdddddr ls) (cdr (cddddr ls)))
10 10
11(define (null? ls) (eq? ls '())) 11(define (null? ls) (eq? ls '()))
12(define (zero? x) (eq? x 0))
13
14(define (remainder x y)
15 (if (> y x)
16 x
17 (remainder (- x y) y)))
18
19(define (quotient x y)
20 (/ x y))
21
22(define (even? x) (zero? (remainder x 2)))
23(define (odd? x) (not (even? x)))
12 24
13(define (length ls) 25(define (length ls)
14 (if (null? ls) 26 (if (null? ls)
@@ -45,9 +57,3 @@
45 57
46(define (sum ls) (fold 0 + ls)) 58(define (sum ls) (fold 0 + ls))
47(define (product ls) (fold 1 * ls)) 59(define (product ls) (fold 1 * ls))
48
49(define (enumerate start stop step)
50 (if (>= start stop)
51 '()
52 (cons start
53 (enumerate (+ start step) stop step))))