root/lang/c/misc/mlisp/lib.l @ 5974

Revision 5974, 1.8 kB (checked in by mokehehe, 5 years ago)

% を mod に変更
load の引数を文字列に

Line 
1
2(setq list
3      (lambda (nil . rest)
4        rest))
5
6(defmacro defun (fname arg body)
7  (list 'setq fname
8        (list 'lambda arg body)))
9
10(defun funcall (fn . x)
11  (apply fn x))
12
13(defun null (x) (eq x nil))
14
15(defun not (x) (eq x nil))
16
17(defun consp (x) (not (atom x)))
18(defun listp (x)
19  (cond ((null x) t)
20        ((consp x) t)
21        (t nil)))
22
23(defun caar (x) (car (car x)))
24(defun cdar (x) (cdr (car x)))
25
26(defun >  (x y) (< y x))
27(defun >= (x y) (not (< x y)))
28(defun <= (x y) (not (< y x)))
29(defun =  (x y) (eq x y))
30(defun /= (x y) (not (eq x y)))
31
32; ���₵��
33(defmacro all (x)
34  (cond ((null x) t)
35        ((car x) (list all (cdr x)))
36        (t nil)))
37
38; ���₵��
39(defmacro any (x)
40  (cond ((null x) nil)
41        ((car x) t)
42        (t (list any (cdr x)))))
43
44(defun length (ls)
45  (cond ((null ls) 0)
46        (t (+ 1 (length (cdr ls))))))
47
48(defun mapcar (fn ls)
49  (cond ((eq ls nil) nil)
50        (t (cons (fn (car ls))
51                 (mapcar fn (cdr ls))))))
52
53
54(defun zerop (x) (eq x 0))
55(defun evenp (x) (eq (% x 2) 0))
56(defun oddp  (x) (eq (% x 2) 1))
57
58(defun inc (x) (+ x 1))
59(defun dec (x) (- x 1))
60
61
62; �Q�‚̃��X�g�������(defun concat (x y)
63  (cond ((null x) y)
64        (t (cons (car x)
65                 (concat (cdr x) y)))))
66
67; �C�ӌ‚̃��X�g�������(defun append (nil . x)
68  (cond ((cdr x) (concat (car x)
69                         (apply append (cdr x))))
70        (t (car x))))
71
72
73
74; ������
75
76;(defmacro if (p tbody ebody)
77;  (list
78;   'cond (list p tbody)
79;   (list t ebody)))
80
81;(defmacro if (p tbody ebody)
82;  (cond (p tbody)
83;        (t ebody)))
84
85(defmacro if (test then else)
86  (cons cond (cons (list test then)
87                   (cond (else (list (list t else)))))))
88
Note: See TracBrowser for help on using the browser.