Skip to content

Commit 3cb61e4

Browse files
committed
Revert lib.lisp
1 parent ce81bc0 commit 3cb61e4

File tree

1 file changed

+53
-57
lines changed

1 file changed

+53
-57
lines changed

lib/lib.lisp

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
(define eq? =)
22

3-
(define (abs x)
4-
(if (< x 0) (- 0 x) x))
3+
(define (abs x) (if (< x 0) (- 0 x) x))
54

65
(define (foldl proc init list)
7-
(if list
8-
(foldl proc (proc init (car list)) (cdr list))
6+
(if list
7+
(foldl proc
8+
(proc init (car list))
9+
(cdr list))
910
init))
1011

1112
(define (foldr proc init list)
12-
(if list
13-
(proc (car list) (foldr proc init (cdr list)))
13+
(if list
14+
(proc (car list)
15+
(foldr proc init (cdr list)))
1416
init))
1517

16-
(define (list . items) (foldr cons nil items))
18+
(define (list . items)
19+
(foldr cons nil items))
1720

1821
(define (reverse list)
19-
(foldl
20-
(lambda (a x) (cons x a))
21-
nil
22-
list))
22+
(foldl (lambda (a x) (cons x a )) nil list))
2323

2424
(define (unary-map proc list)
25-
(foldr
26-
(lambda (x rest) (cons (proc x) rest))
27-
nil
28-
list))
25+
(foldr (lambda (x rest) (cons (proc x) rest))
26+
nil
27+
list))
2928

3029
(define (map proc . arg-lists)
31-
(if (car arg-lists)
32-
(cons
33-
(apply proc (unary-map car arg-lists))
34-
(apply (quote map) (cons proc (unary-map cdr arg-lists))))
30+
(if (car arg-lists)
31+
(cons (apply proc (unary-map car arg-lists))
32+
(apply 'map (cons proc
33+
(unary-map cdr arg-lists))))
3534
nil))
3635

3736
(define (append a b) (foldr cons b a))
@@ -41,61 +40,58 @@
4140
(define (cadr x) (car (cdr x)))
4241

4342
(defmacro (quasiquote x)
44-
(if (pair? x)
45-
(if (eq? (car x) (quote unquote))
46-
(cadr x)
47-
(if (eq? (caar x) (quote unquote-splicing))
48-
(list
49-
(quote append)
50-
(cadr (car x))
51-
(list (quote quasiquote) (cdr x)))
52-
(list
53-
(quote cons)
54-
(list (quote quasiquote) (car x))
55-
(list (quote quasiquote) (cdr x)))))
56-
(list (quote quote) x)))
43+
(if (pair? x)
44+
(if (eq? (car x) 'unquote)
45+
(cadr x)
46+
(if (eq? (caar x) 'unquote-splicing)
47+
(list 'append
48+
(cadr (car x))
49+
(list 'quasiquote (cdr x)))
50+
(list 'cons
51+
(list 'quasiquote (car x))
52+
(list 'quasiquote (cdr x)))))
53+
(list 'quote x)))
5754

5855
(defmacro (let defs . body)
59-
(quasiquote
60-
((lambda (unquote (map car defs)) (unquote-splicing body))
61-
(unquote-splicing (map cadr defs)))))
56+
`((lambda ,(map car defs) ,@body)
57+
,@(map cadr defs)))
6258

6359
(define +
64-
(let
65-
((old+ +))
66-
(lambda xs (foldl old+ 0 xs))))
60+
(let ((old+ +))
61+
(lambda xs (foldl old+ 0 xs))))
6762

6863
(define -
69-
(let
70-
((old- -))
71-
(lambda xs (foldl old- (car xs) (cdr xs)))))
64+
(let ((old- -))
65+
(lambda xs (foldl old- (car xs) (cdr xs)))))
7266

7367
(define *
74-
(let
75-
((old* *))
76-
(lambda xs (foldl old* (car xs) (cdr xs)))))
68+
(let ((old* *))
69+
(lambda xs (foldl old* (car xs) (cdr xs)))))
7770

7871
(define /
79-
(let
80-
((old/ /))
81-
(lambda xs (foldl old/ (car xs) (cdr xs)))))
72+
(let ((old/ /))
73+
(lambda xs (foldl old/ (car xs) (cdr xs)))))
74+
8275

8376
(define (last x)
84-
(if (pair? x)
77+
(if (pair? x)
8578
(if (pair? (cdr x))
86-
(last (cdr x))
87-
(if (= nil (cdr x))
88-
(car x)
89-
(cdr x)))
79+
(last (cdr x))
80+
(if (= nil (cdr x))
81+
(car x)
82+
(cdr x)))
9083
(x)))
9184

9285
(define (list-length x)
93-
(if (pair? x)
86+
(if (pair? x)
9487
(+ 1 (list-length (cdr x)))
95-
(if (= nil x) 0 1)))
88+
(if (= nil x)
89+
0
90+
1)))
9691

9792
(define (length x)
98-
(if (pair? x)
93+
(if (pair? x)
9994
(list-length x)
100-
(if (string? x) (string-length x) nil)))
101-
95+
(if (string? x)
96+
(string-length x)
97+
nil)))

0 commit comments

Comments
 (0)