-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc.txt
More file actions
189 lines (136 loc) · 2.91 KB
/
Copy pathsrc.txt
File metadata and controls
189 lines (136 loc) · 2.91 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# comment
### SUBR ###
### atom ###
# (atom X)
# Xがatomであればt、そうでなければnilを返す
(atom 1)
# -> t
(atom 1.1)
# -> t
(atom (quote a))
# -> t
(atom nil)
# -> t
(atom (quote (1 2)))
# -> nil
### car ###
# (car X)
# cons(X)のcarを返す
(car (quote (1 2 3)))
# -> 1
### cdr ###
# (cdr X)
# cons(X)のcdrを返す
(cdr (quote (1 2 3)))
# -> (2 3)
### cons ###
# (cons X Y)
# XとYをそれぞれconsのcarとcdrにして返す
(cons (quote (1 2 3)) (quote (4 5 6)))
# -> ((1 2 3) 4 5 6)
### eq ###
# (eq X Y)
# XとYが同値であればt、そうでなければnilを返す
(eq 1 1)
# -> t
(eq 1.1 1.1)
# -> t
(eq (quote a) (quote a))
# -> t
(eq (quote (1 2)) (quote (1 2)))
# -> t
(eq 1 2)
# -> nil
(eq (quote (1 2)) (quote (1 3)))
# -> nil
### eval ###
# (eval X)
# MyLispの処理系と同じようにXを評価する
(eval 1)
# -> 1
(eval (quote ((lambda (x y) (+ x y)) 1 2)))
# -> 3
### numberp ###
# (numberp X)
# Xがnumberであればt、そうでなければnilを返す
(numberp 1)
# -> t
(numberp 1.1)
# -> t
(numberp nil)
# -> nil
(numberp (quote a))
# -> nil
### print ###
# (print X)
# Xを標準出力に書き出し、それ自体を返す
(print 1)
# 1
# -> 1
(print (quote a))
# a
# -> a
### FSUBR ###
### + ###
# (+ X1 X2 X3 ... Xn)
# X1, X2, X3, ... Xnを順次足し合わせて返す
# 値はC言語のdoubleの計算精度、範囲である
(+ 1 2 3)
# -> 6
### - ###
# (- X1 X2 X3 ... Xn)
# X1からX2, X3, ... Xnを順次引いて返す
# 値はC言語のdoubleの計算精度、範囲である
(- 1 2 3)
# -> -4
### * ###
# (* X1 X2 X3 ... Xn)
# X1, X2, X3, ... Xnを順次掛けて合わせて返す
# 値はC言語のdoubleの計算精度、範囲である
(* 1 2 3)
# -> 6
### / ###
# (/ X1 X2 X3 ... Xn)
# X1からX2, X3, ... Xnを順次割って返す
# 値はC言語のdoubleの計算精度、範囲である
(/ 1 2 3)
# -> 0.166667 = 1 / 6
### % ###
# 未実装
# モジュロ演算を順次実行する関数になる予定
### cond ###
# (cond (X1 Y11 Y12 ... Y1n) ... (Xn Yn1 Yn2 ... Ynn))
# x1 ... Xnがtと評価されるまで引数を順に確認し、
# tと評価されたリストのYn1, Yn2 ... Ynnを評価し、最終の評価値を返す
(cond ((eq 1 2) (print 1)) ((eq 2 2) (print 2)) (t (print 3)))
# 2
# -> 2
(cond ((eq 1 2) (print 1)) ((eq 2 3) (print 2)) (t (print 3)))
# 3
# -> 3
### define ###
# (define X Y)
# Xで指定されたatomにYをバインドする
(define x 1)
# -> x
# x = 1
(define x (quote (1 2 3)))
# -> x
# x = (1 2 3)
### quote ###
# (quote X)
# Xを評価せずにそのまま返す
(quote a)
# -> a
(quote (1 2 3))
# -> (1 2 3)
### lambdaの扱い ###
# lambdaを関数として扱うことができる
((lambda (x y) (+ x y)) 1 2)
# -> 3
# lambdaをatomにバインドして関数として呼び出すこともできる
(define func (quote (lambda (x y) (+ x y))))
# -> func
# func = (lambda (x y) (+ x y))
(func 1 2)
# -> 3