-
Notifications
You must be signed in to change notification settings - Fork 40
/
common.lisp
41 lines (41 loc) · 1.11 KB
/
common.lisp
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
(define null? not)
(define err? (lambda (x) (eq? x 'ERR)))
(define number? (lambda (x) (eq? (* 0 x) 0)))
(define pair? (lambda (x) (not (err? (cdr x)))))
(define symbol?
(lambda (x)
(and
x
(not (err? x))
(not (number? x))
(not (pair? x)))))
(define atom?
(lambda (x)
(or
(not x)
(symbol? x))))
(define list?
(lambda (x)
(if (not x)
#t
(if (pair? x)
(list? (cdr x))
()))))
(define equal?
(lambda (x y)
(or
(eq? x y)
(and
(pair? x)
(pair? y)
(equal? (car x) (car y))
(equal? (cdr x) (cdr y))))))
(define negate (lambda (n) (- 0 n)))
(define > (lambda (x y) (< y x)))
(define <= (lambda (x y) (not (< y x))))
(define >= (lambda (x y) (not (< x y))))
(define = (lambda (x y) (eq? (- x y) 0)))
(define list (lambda args args))
(define cadr (lambda (x) (car (cdr x))))
(define caddr (lambda (x) (car (cdr (cdr x)))))
(define begin (lambda (x . args) (if args (begin . args) x)))