-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.scm
More file actions
39 lines (33 loc) · 781 Bytes
/
helpers.scm
File metadata and controls
39 lines (33 loc) · 781 Bytes
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
;; Author: Isaac H. Lopez Diaz <[email protected]>
;; Description: Functions from The Little Schemer
;; Test to see if value is an atom
(define atom?
(lambda (x)
(and (not (pair? x))
(not (null? x)))))
;; Increase by 1 the current number
(define add1
(lambda (x)
(+ x 1)))
;; Decrease by 1 the current number
(define sub1
(lambda (x)
(- x 1)))
;; Test whether an atom is on a list
(define member?
(lambda (a lat)
(cond
((null? lat) #f)
(else (or (eq? a (car lat))
(member? a (cdr lat)))))))
;; Test whether a number is equal to one
(define one?
(lambda (x)
(= x 1)))
;; Function that extracts the leftmost atom
(define leftmost
(lambda (l)
(cond
((atom? (car l))
(car l))
(else (leftmost (car l))))))