-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.scm
71 lines (59 loc) · 1.2 KB
/
init.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(define (not bool)
(if bool #f #t))
(define (< a b) (> b a))
(define (= a b) (eq? a b))
(define (!= a b) (not (= a b)))
(define (>= a b) (not (< a b)))
(define (<= a b) (not (> a b)))
(define (zero? n)
(eq? n 0))
(define (negative? n)
(> 0 n))
(define (positive? n)
(> n 0))
(define (abs num)
(if (negative? num)
(* num -1)
num))
(define (even? a)
(if (= 0 a)
#t
(if (> a 0)
(if (= (/ a 2) (/ (+ a 1) 2))
#t
#f)
(if (= (/ a 2) (/ (- a 1) 2))
#t
#f)
)
)
)
(define (nth n l)
(if (< n 1)
(error "(nth): index error")
(if (eq? l nil)
(error "(nth): index out of range")
(if (= n 1)
(car l)
(nth (- n 1) (cdr l) )))))
(define (set_nth n l o)
(if (< n 1)
(error "(set_nth): index error")
(if (eq? l nil)
(error "(set_nth): index out of range")
(if (= n 1)
(set-car! l o)
(set_nth (- n 1) (cdr l) o )))))
(define (indexOfS? string l)
(define (indexOfS?_helper accu string l)
(if (eq? l nil)
-1
(if (string=? string (car l))
accu
(indexOfS?_helper (+ accu 1) string (cdr l))
)))
(indexOfS?_helper 1 string l))
(define (newline) (display "\n"))
(define (error msg)
(display msg) (newline)
abort)