nendo 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmark/benchmark.nnd +27 -5
- data/lib/debug/syslog.nndc +24 -18
- data/lib/init.nnd +12 -28
- data/lib/init.nndc +18733 -14143
- data/lib/nendo/experimental.nnd +120 -0
- data/lib/nendo/experimental.nndc +1069 -0
- data/lib/nendo/test.nndc +1122 -879
- data/lib/nendo.rb +67 -16
- data/lib/rfc/json.nndc +486 -375
- data/lib/srfi-1.nndc +12775 -9853
- data/lib/srfi-2.nndc +810 -552
- data/lib/srfi-26.nndc +2615 -1838
- data/lib/text/html-lite.nndc +2286 -1737
- data/lib/text/tree.nndc +136 -103
- data/lib/util/combinations.nndc +4747 -3436
- data/lib/util/list.nndc +3417 -2355
- data/lib/util/match.nndc +53574 -36147
- data/test/nendo-util-test.nnd +318 -32
- data/test/nendo_spec.rb +65 -12
- data/test/rspec_formatter_for_emacs.rb +25 -0
- data/test/syntax_spec.rb +2 -0
- metadata +86 -12
data/test/nendo-util-test.nnd
CHANGED
@@ -2,27 +2,8 @@
|
|
2
2
|
;; test for nendo's core utility
|
3
3
|
|
4
4
|
(use nendo.test)
|
5
|
-
(test-start "nendo's core utility")
|
6
|
-
|
7
|
-
;;===================================================================
|
8
|
-
(test-section "pretty-print-to-string")
|
9
|
-
(define test-sexp1 '(a (b (c))))
|
10
|
-
(define test-sexp2 '(define (function1 a b c) (+ a b c)))
|
11
|
-
|
12
|
-
(test* "pretty-print-to-string"
|
13
|
-
(string-join
|
14
|
-
'("(a\n"
|
15
|
-
" (b\n"
|
16
|
-
" (c)))\n"))
|
17
|
-
(pretty-print-to-string test-sexp1))
|
18
|
-
|
19
|
-
(test* "pretty-print-to-string"
|
20
|
-
(string-join
|
21
|
-
'("(define\n"
|
22
|
-
" (function1 a b c)\n"
|
23
|
-
" (+ a b c))\n"))
|
24
|
-
(pretty-print-to-string test-sexp2))
|
25
5
|
|
6
|
+
(test-start "nendo's core utility")
|
26
7
|
|
27
8
|
;;-------------------------------------------------------------------
|
28
9
|
(test-section "disasm")
|
@@ -32,8 +13,8 @@
|
|
32
13
|
var))
|
33
14
|
|
34
15
|
(test* "disasm info"
|
35
|
-
" file: ./test/nendo-util-test.nnd
|
36
|
-
lineno:
|
16
|
+
" file: ./test/nendo-util-test.nnd
|
17
|
+
lineno: 11
|
37
18
|
source:
|
38
19
|
(define
|
39
20
|
(dummy-function arg1)
|
@@ -46,8 +27,7 @@
|
|
46
27
|
(%let
|
47
28
|
((var
|
48
29
|
(+ arg1 1))) var)))
|
49
|
-
"
|
50
|
-
(disasm 'dummy-function 'info))
|
30
|
+
" (disasm 'dummy-function 'info))
|
51
31
|
(test* "disasm source "
|
52
32
|
'(define (dummy-function arg1) (let1 var (+ arg1 1) var))
|
53
33
|
(disasm 'dummy-function 'source))
|
@@ -67,16 +47,19 @@ trampCall(
|
|
67
47
|
___lambda = lambda { |_var|
|
68
48
|
begin
|
69
49
|
trampCall(_var)
|
70
|
-
rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:
|
50
|
+
rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:13\"] + __e.backtrace ) ; raise __e
|
71
51
|
end
|
72
52
|
} ; ___lambda.call(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
53
|
+
begin
|
54
|
+
embedBacktraceInfo( \"./test/nendo-util-test.nnd\", 12 );
|
55
|
+
__PLMARK_ARGS2(
|
56
|
+
begin
|
57
|
+
trampCall(_arg1)
|
58
|
+
rescue => __e ; __e.set_backtrace( [\"./test/nendo-util-test.nnd:12\"] + __e.backtrace ) ; raise __e
|
59
|
+
end ,
|
60
|
+
1
|
61
|
+
)
|
62
|
+
end
|
80
63
|
)
|
81
64
|
end
|
82
65
|
}
|
@@ -85,5 +68,308 @@ trampCall(
|
|
85
68
|
)"
|
86
69
|
(disasm 'dummy-function))
|
87
70
|
|
71
|
+
|
72
|
+
;;===================================================================
|
73
|
+
(test-section "pretty-print-to-string")
|
74
|
+
(define test-sexp1 '(a (b (c))))
|
75
|
+
(define test-sexp2 '(define (function1 a b c) (+ a b c)))
|
76
|
+
|
77
|
+
(test* "pretty-print-to-string"
|
78
|
+
(string-join
|
79
|
+
'("(a\n"
|
80
|
+
" (b\n"
|
81
|
+
" (c)))\n"))
|
82
|
+
(pretty-print-to-string test-sexp1))
|
83
|
+
|
84
|
+
(test* "pretty-print-to-string"
|
85
|
+
(string-join
|
86
|
+
'("(define\n"
|
87
|
+
" (function1 a b c)\n"
|
88
|
+
" (+ a b c))\n"))
|
89
|
+
(pretty-print-to-string test-sexp2))
|
90
|
+
|
91
|
+
|
92
|
+
(define (wrap-str str)
|
93
|
+
(+ "[" str "]"))
|
94
|
+
|
95
|
+
|
96
|
+
;;-------------------------------------------------------------------
|
97
|
+
(test-section "map for Enumerable")
|
98
|
+
|
99
|
+
(test* "map-pable? no"
|
100
|
+
#f
|
101
|
+
(%%map-able?
|
102
|
+
(lambda (x) x)
|
103
|
+
' (1 2)))
|
104
|
+
|
105
|
+
(test* "map-pable? yes"
|
106
|
+
#t
|
107
|
+
(%%map-able?
|
108
|
+
(lambda (x) x)
|
109
|
+
'#(1 2)))
|
110
|
+
|
111
|
+
(test* "map-pable? yes"
|
112
|
+
#t
|
113
|
+
(%%map-able?
|
114
|
+
(lambda (x) x)
|
115
|
+
(Range.new 0 100)))
|
116
|
+
|
117
|
+
(test* "map-pable? yes"
|
118
|
+
#t
|
119
|
+
(%%map-able?
|
120
|
+
(lambda (x) x)
|
121
|
+
(hash-table eq? '("a" 1) '("b" 2))))
|
122
|
+
|
123
|
+
(test* "%%map"
|
124
|
+
'#("[a]" "[b]" "[C]")
|
125
|
+
(%%map
|
126
|
+
wrap-str
|
127
|
+
'#("a" "b" "C")))
|
128
|
+
|
129
|
+
(test* "%map (for vector)"
|
130
|
+
'#("[a]" "[b]" "[C]")
|
131
|
+
(%map
|
132
|
+
wrap-str
|
133
|
+
'#("a" "b" "C")))
|
134
|
+
|
135
|
+
(test* "map (for vector)"
|
136
|
+
'#("[a]" "[b]" "[C]")
|
137
|
+
(map
|
138
|
+
wrap-str
|
139
|
+
'#("a" "b" "C")))
|
140
|
+
|
141
|
+
(test* "map (for list)"
|
142
|
+
'("[a]" "[b]" "[C]")
|
143
|
+
(map
|
144
|
+
wrap-str
|
145
|
+
'("a" "b" "C")))
|
146
|
+
|
147
|
+
(test* "map (for lists)"
|
148
|
+
'("[1:3:5]" "[2:4:6]")
|
149
|
+
(map
|
150
|
+
(lambda (x y z) (+ "[" x ":" y ":" z "]"))
|
151
|
+
'("1" "2")
|
152
|
+
'("3" "4")
|
153
|
+
'("5" "6")))
|
154
|
+
|
155
|
+
;;-------------------------------------------------------------------
|
156
|
+
(test-section "for-each for Enumerable")
|
157
|
+
|
158
|
+
(test* "for-each-pable? no"
|
159
|
+
#f
|
160
|
+
(%%for-each-able?
|
161
|
+
(lambda (x) x)
|
162
|
+
' (1 2)))
|
163
|
+
|
164
|
+
(test* "for-each-pable? yes"
|
165
|
+
#t
|
166
|
+
(%%for-each-able?
|
167
|
+
(lambda (x) x)
|
168
|
+
'#(1 2)))
|
169
|
+
|
170
|
+
(test* "for-each-pable? yes"
|
171
|
+
#t
|
172
|
+
(%%for-each-able?
|
173
|
+
(lambda (x) x)
|
174
|
+
(Range.new 0 100)))
|
175
|
+
|
176
|
+
(test* "for-each-pable? yes"
|
177
|
+
#t
|
178
|
+
(%%for-each-able?
|
179
|
+
(lambda (x) x)
|
180
|
+
(hash-table eq? '("a" 1) '("b" 2))))
|
181
|
+
|
182
|
+
(test* "%%for-each"
|
183
|
+
'("[a]" "[b]" "[C]")
|
184
|
+
(let1 result '()
|
185
|
+
(%%for-each
|
186
|
+
(lambda (x) (set! result
|
187
|
+
(cons (wrap-str x) result)))
|
188
|
+
'#("a" "b" "C"))
|
189
|
+
(reverse result)))
|
190
|
+
|
191
|
+
(test* "%for-each (for vector)"
|
192
|
+
'("[a]" "[b]" "[C]")
|
193
|
+
(let1 result '()
|
194
|
+
(%for-each
|
195
|
+
(lambda (x) (set! result
|
196
|
+
(cons (wrap-str x) result)))
|
197
|
+
'#("a" "b" "C"))
|
198
|
+
(reverse result)))
|
199
|
+
|
200
|
+
(test* "for-each (for vector)"
|
201
|
+
'("[a]" "[b]" "[C]")
|
202
|
+
(let1 result '()
|
203
|
+
(for-each
|
204
|
+
(lambda (x) (set! result
|
205
|
+
(cons (wrap-str x) result)))
|
206
|
+
'#("a" "b" "C"))
|
207
|
+
(reverse result)))
|
208
|
+
|
209
|
+
(test* "for-each (for list)"
|
210
|
+
'("[a]" "[b]" "[C]")
|
211
|
+
(let1 result '()
|
212
|
+
(for-each
|
213
|
+
(lambda (x) (set! result
|
214
|
+
(cons (wrap-str x) result)))
|
215
|
+
'("a" "b" "C"))
|
216
|
+
(reverse result)))
|
217
|
+
|
218
|
+
(test* "for-each (for lists)"
|
219
|
+
'("[1:3:5]" "[2:4:6]")
|
220
|
+
(let1 result '()
|
221
|
+
(for-each
|
222
|
+
(lambda (x y z)
|
223
|
+
(set! result
|
224
|
+
(cons
|
225
|
+
(+ "[" x ":" y ":" z "]")
|
226
|
+
result)))
|
227
|
+
|
228
|
+
'("1" "2")
|
229
|
+
'("3" "4")
|
230
|
+
'("5" "6"))
|
231
|
+
(reverse result)))
|
232
|
+
|
233
|
+
|
234
|
+
;;-------------------------------------------------------------------
|
235
|
+
(test-section "filter for Enumerable")
|
236
|
+
|
237
|
+
(test* "filter-pable? no"
|
238
|
+
#f
|
239
|
+
(%%filter-able?
|
240
|
+
(lambda (x) x)
|
241
|
+
' (1 2)))
|
242
|
+
|
243
|
+
(test* "filter-pable? yes"
|
244
|
+
#t
|
245
|
+
(%%filter-able?
|
246
|
+
(lambda (x) x)
|
247
|
+
'#(1 2)))
|
248
|
+
|
249
|
+
(test* "filter-pable? yes"
|
250
|
+
#t
|
251
|
+
(%%filter-able?
|
252
|
+
(lambda (x) x)
|
253
|
+
(Range.new 0 100)))
|
254
|
+
|
255
|
+
(test* "filter-pable? yes"
|
256
|
+
#t
|
257
|
+
(%%filter-able?
|
258
|
+
(lambda (x) x)
|
259
|
+
(hash-table eq? '("a" 1) '("b" 2))))
|
260
|
+
|
261
|
+
(test* "%%filter"
|
262
|
+
'#("b")
|
263
|
+
(%%filter
|
264
|
+
(lambda (x) (= "b" x))
|
265
|
+
'#("a" "b" "C")))
|
266
|
+
|
267
|
+
(test* "%filter (for vector)"
|
268
|
+
'#("b")
|
269
|
+
(%filter
|
270
|
+
(lambda (x) (= "b" x))
|
271
|
+
'#("a" "b" "C")))
|
272
|
+
|
273
|
+
(test* "filter (for vector1)"
|
274
|
+
'#("b")
|
275
|
+
(filter
|
276
|
+
(lambda (x) (= "b" x))
|
277
|
+
'#("a" "b" "C")))
|
278
|
+
|
279
|
+
(test* "filter (for vector2)"
|
280
|
+
'#("a" "C")
|
281
|
+
(filter
|
282
|
+
(lambda (x) (not (= "b" x)))
|
283
|
+
'#("a" "b" "C")))
|
284
|
+
|
285
|
+
(test* "filter (for list)"
|
286
|
+
'("C")
|
287
|
+
(filter
|
288
|
+
(lambda (x) (= "C" x))
|
289
|
+
'("a" "b" "C")))
|
290
|
+
|
291
|
+
|
292
|
+
;;-------------------------------------------------------------------
|
293
|
+
(test-section "Enumerable on srfi-1")
|
294
|
+
(use srfi-1)
|
295
|
+
|
296
|
+
(test* "map (for vector)"
|
297
|
+
'#("[a]" "[b]" "[C]")
|
298
|
+
(map
|
299
|
+
wrap-str
|
300
|
+
'#("a" "b" "C")))
|
301
|
+
|
302
|
+
(test* "map (for Range)"
|
303
|
+
'#(10 11 12)
|
304
|
+
(map
|
305
|
+
(lambda (x) x)
|
306
|
+
(Range.new 10 12)))
|
307
|
+
|
308
|
+
(test* "map (for Enumerator)"
|
309
|
+
'#("[one]" "[two]" "[three]")
|
310
|
+
(map
|
311
|
+
wrap-str
|
312
|
+
(Enumerator.new
|
313
|
+
(&block (v)
|
314
|
+
(v.yield "one")
|
315
|
+
(v.yield "two")
|
316
|
+
(v.yield "three")))))
|
317
|
+
|
318
|
+
|
319
|
+
(test* "for-each (for vector)"
|
320
|
+
'("[a]" "[b]" "[C]")
|
321
|
+
(let1 result '()
|
322
|
+
(for-each
|
323
|
+
(lambda (x) (set! result
|
324
|
+
(cons (wrap-str x) result)))
|
325
|
+
'#("a" "b" "C"))
|
326
|
+
(reverse result)))
|
327
|
+
|
328
|
+
(test* "for-each (for Range)"
|
329
|
+
'(10 11 12)
|
330
|
+
(let1 result '()
|
331
|
+
(for-each
|
332
|
+
(lambda (x) (set! result
|
333
|
+
(cons x result)))
|
334
|
+
(Range.new 10 12))
|
335
|
+
(reverse result)))
|
336
|
+
|
337
|
+
(test* "for-each (for Enumerable)"
|
338
|
+
'("[one]" "[two]" "[three]")
|
339
|
+
(let1 result '()
|
340
|
+
(for-each
|
341
|
+
(lambda (x) (set! result
|
342
|
+
(cons (wrap-str x) result)))
|
343
|
+
(Enumerator.new
|
344
|
+
(&block (v)
|
345
|
+
(v.yield "one")
|
346
|
+
(v.yield "two")
|
347
|
+
(v.yield "three"))))
|
348
|
+
(reverse result)))
|
349
|
+
|
350
|
+
(test* "filter (for vector)"
|
351
|
+
'#("b")
|
352
|
+
(filter
|
353
|
+
(lambda (x) (= "b" x))
|
354
|
+
'#("a" "b" "C")))
|
355
|
+
|
356
|
+
(test* "filter (for Range)"
|
357
|
+
'#(11)
|
358
|
+
(filter
|
359
|
+
(lambda (x) (= 11 x))
|
360
|
+
(Range.new 10 1000)))
|
361
|
+
|
362
|
+
(test* "filter (for Enumerable)"
|
363
|
+
'#("one" "three")
|
364
|
+
(filter
|
365
|
+
(lambda (x) (not (= "two" x)))
|
366
|
+
(Enumerator.new
|
367
|
+
(&block (v)
|
368
|
+
(v.yield "one")
|
369
|
+
(v.yield "two")
|
370
|
+
(v.yield "three")))))
|
371
|
+
|
372
|
+
|
373
|
+
|
88
374
|
;;===================================================================
|
89
375
|
(test-end)
|
data/test/nendo_spec.rb
CHANGED
@@ -335,6 +335,7 @@ end
|
|
335
335
|
describe Nendo, "when call evalStr() with `+' function" do
|
336
336
|
before do
|
337
337
|
@nendo = Nendo::Core.new()
|
338
|
+
@nendo.setDisplayErrors( false )
|
338
339
|
end
|
339
340
|
it "should" do
|
340
341
|
@nendo.evalStr( " (+ 1) " ).should == "1"
|
@@ -361,6 +362,7 @@ end
|
|
361
362
|
describe Nendo, "when call evalStr() with `-' function" do
|
362
363
|
before do
|
363
364
|
@nendo = Nendo::Core.new()
|
365
|
+
@nendo.setDisplayErrors( false )
|
364
366
|
end
|
365
367
|
it "should" do
|
366
368
|
@nendo.evalStr( " (- 1) " ).should == "-1"
|
@@ -383,6 +385,7 @@ end
|
|
383
385
|
describe Nendo, "when call evalStr() with `*' function" do
|
384
386
|
before do
|
385
387
|
@nendo = Nendo::Core.new()
|
388
|
+
@nendo.setDisplayErrors( false )
|
386
389
|
end
|
387
390
|
it "should" do
|
388
391
|
@nendo.evalStr( " (* 1) " ).should == "1"
|
@@ -407,6 +410,7 @@ end
|
|
407
410
|
describe Nendo, "when call evalStr() with `/' function" do
|
408
411
|
before do
|
409
412
|
@nendo = Nendo::Core.new()
|
413
|
+
@nendo.setDisplayErrors( false )
|
410
414
|
end
|
411
415
|
it "should" do
|
412
416
|
@nendo.evalStr( " (/ 1) " ).should == "1"
|
@@ -433,6 +437,7 @@ end
|
|
433
437
|
describe Nendo, "when call evalStr() with `%' function" do
|
434
438
|
before do
|
435
439
|
@nendo = Nendo::Core.new()
|
440
|
+
@nendo.setDisplayErrors( false )
|
436
441
|
end
|
437
442
|
it "should" do
|
438
443
|
@nendo.evalStr( " (% 1) " ).should == "0"
|
@@ -455,6 +460,7 @@ end
|
|
455
460
|
describe Nendo, "when call evalStr() with `quotient' function" do
|
456
461
|
before do
|
457
462
|
@nendo = Nendo::Core.new()
|
463
|
+
@nendo.setDisplayErrors( false )
|
458
464
|
end
|
459
465
|
it "should" do
|
460
466
|
@nendo.evalStr( " (quotient 2 1) " ).should == "2"
|
@@ -478,6 +484,7 @@ end
|
|
478
484
|
describe Nendo, "when call evalStr() with `remainder' function" do
|
479
485
|
before do
|
480
486
|
@nendo = Nendo::Core.new()
|
487
|
+
@nendo.setDisplayErrors( false )
|
481
488
|
end
|
482
489
|
it "should" do
|
483
490
|
@nendo.evalStr( " (remainder 2 1) " ).should == "0"
|
@@ -501,6 +508,7 @@ end
|
|
501
508
|
describe Nendo, "when call evalStr() with `modulo' function" do
|
502
509
|
before do
|
503
510
|
@nendo = Nendo::Core.new()
|
511
|
+
@nendo.setDisplayErrors( false )
|
504
512
|
end
|
505
513
|
it "should" do
|
506
514
|
@nendo.evalStr( " (modulo 2 1) " ).should == "0"
|
@@ -718,6 +726,7 @@ end
|
|
718
726
|
describe Nendo, "when read various vector expressions" do
|
719
727
|
before do
|
720
728
|
@nendo = Nendo::Core.new()
|
729
|
+
@nendo.setDisplayErrors( false )
|
721
730
|
end
|
722
731
|
it "should" do
|
723
732
|
@nendo.evalStr( " '() " ).should == "()"
|
@@ -743,6 +752,7 @@ end
|
|
743
752
|
describe Nendo, "when call evalStr() with built-in functions" do
|
744
753
|
before do
|
745
754
|
@nendo = Nendo::Core.new()
|
755
|
+
@nendo.setDisplayErrors( false )
|
746
756
|
end
|
747
757
|
it "should" do
|
748
758
|
@nendo.evalStr( " (car '(1 2 3 4)) " ).should == "1"
|
@@ -936,6 +946,7 @@ end
|
|
936
946
|
describe Nendo, "when call evalStr() with undefined variable" do
|
937
947
|
before do
|
938
948
|
@nendo = Nendo::Core.new()
|
949
|
+
@nendo.setDisplayErrors( false )
|
939
950
|
end
|
940
951
|
it "should" do
|
941
952
|
lambda { @nendo.evalStr( " true " ) }.should_not raise_error
|
@@ -952,6 +963,7 @@ end
|
|
952
963
|
describe Nendo, "when call evalStr() with built-in special forms" do
|
953
964
|
before do
|
954
965
|
@nendo = Nendo::Core.new()
|
966
|
+
@nendo.setDisplayErrors( false )
|
955
967
|
end
|
956
968
|
it "should" do
|
957
969
|
@nendo.evalStr( " (begin 1) " ).should == "1"
|
@@ -980,14 +992,14 @@ EOS
|
|
980
992
|
@nendo.evalStr( " (letrec ((a 22)(b 33)) (%let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
|
981
993
|
@nendo.evalStr( " (letrec ((a (%let ((b 2)) (+ 100 b)))) a) " ).should == "102"
|
982
994
|
@nendo.evalStr( <<EOS
|
983
|
-
(letrec ((func1 (lambda (
|
984
|
-
(func2 (lambda (
|
995
|
+
(letrec ((func1 (lambda () 13))
|
996
|
+
(func2 (lambda () (* 2 (func1)))))
|
985
997
|
(list (func2) (func1)))
|
986
998
|
EOS
|
987
999
|
).should == "(26 13)"
|
988
1000
|
@nendo.evalStr( <<EOS
|
989
|
-
(letrec ((func2 (lambda (
|
990
|
-
(func1 (lambda (
|
1001
|
+
(letrec ((func2 (lambda () (* 2 (func1))))
|
1002
|
+
(func1 (lambda () 7)))
|
991
1003
|
(list (func2) (func1)))
|
992
1004
|
EOS
|
993
1005
|
).should == "(14 7)"
|
@@ -1015,12 +1027,15 @@ EOS
|
|
1015
1027
|
@nendo.evalStr( " (apply1 list '(1 2 3))" ).should == "(1 2 3)"
|
1016
1028
|
lambda { @nendo.evalStr( " (error \"My Runtime Error\") " ) }.should raise_error( RuntimeError, /My Runtime Error/ )
|
1017
1029
|
lambda { @nendo.evalStr( " (error \"My Runtime Error\" '(a b c)) " ) }.should raise_error( RuntimeError, /My Runtime Error [(]a b c[)]/ )
|
1030
|
+
@nendo.evalStr( "((lambda (arg1) (+ 1 arg1)) 2)" ).should == "3"
|
1031
|
+
lambda { @nendo.evalStr( "((lambda (arg1) (+ 1 arg1)))" ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
|
1018
1032
|
end
|
1019
1033
|
end
|
1020
1034
|
|
1021
1035
|
describe Nendo, "when call evalStr() with built-in special forms (renamed symbol)" do
|
1022
1036
|
before do
|
1023
1037
|
@nendo = Nendo::Core.new()
|
1038
|
+
@nendo.setDisplayErrors( false )
|
1024
1039
|
@nendo.loadInitFile
|
1025
1040
|
end
|
1026
1041
|
it "should" do
|
@@ -1050,14 +1065,14 @@ EOS
|
|
1050
1065
|
@nendo.evalStr( " (/nendo/core/letrec ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
|
1051
1066
|
@nendo.evalStr( " (/nendo/core/letrec ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
|
1052
1067
|
@nendo.evalStr( <<EOS
|
1053
|
-
(/nendo/core/letrec ((func1 (/nendo/core/lambda (
|
1054
|
-
(func2 (/nendo/core/lambda (
|
1068
|
+
(/nendo/core/letrec ((func1 (/nendo/core/lambda () 13))
|
1069
|
+
(func2 (/nendo/core/lambda () (* 2 (func1)))))
|
1055
1070
|
(list (func2) (func1)))
|
1056
1071
|
EOS
|
1057
1072
|
).should == "(26 13)"
|
1058
1073
|
@nendo.evalStr( <<EOS
|
1059
|
-
(/nendo/core/letrec ((func2 (/nendo/core/lambda (
|
1060
|
-
(func1 (/nendo/core/lambda (
|
1074
|
+
(/nendo/core/letrec ((func2 (/nendo/core/lambda () (* 2 (func1))))
|
1075
|
+
(func1 (/nendo/core/lambda () 7)))
|
1061
1076
|
(list (func2) (func1)))
|
1062
1077
|
EOS
|
1063
1078
|
).should == "(14 7)"
|
@@ -1084,6 +1099,7 @@ end
|
|
1084
1099
|
describe Nendo, "when redefined built-in functions(1)." do
|
1085
1100
|
before do
|
1086
1101
|
@nendo = Nendo::Core.new()
|
1102
|
+
@nendo.setDisplayErrors( false )
|
1087
1103
|
@nendo.loadInitFile
|
1088
1104
|
end
|
1089
1105
|
it "should" do
|
@@ -1199,6 +1215,7 @@ end
|
|
1199
1215
|
describe Nendo, "when use #xxxx syntax " do
|
1200
1216
|
before do
|
1201
1217
|
@nendo = Nendo::Core.new()
|
1218
|
+
@nendo.setDisplayErrors( false )
|
1202
1219
|
@nendo.loadInitFile
|
1203
1220
|
end
|
1204
1221
|
it "should" do
|
@@ -1278,6 +1295,7 @@ end
|
|
1278
1295
|
describe Nendo, "when use regexp litteral and library functions " do
|
1279
1296
|
before do
|
1280
1297
|
@nendo = Nendo::Core.new()
|
1298
|
+
@nendo.setDisplayErrors( false )
|
1281
1299
|
@nendo.loadInitFile
|
1282
1300
|
end
|
1283
1301
|
it "should" do
|
@@ -1792,6 +1810,7 @@ end
|
|
1792
1810
|
describe Nendo, "when use values " do
|
1793
1811
|
before do
|
1794
1812
|
@nendo = Nendo::Core.new()
|
1813
|
+
@nendo.setDisplayErrors( false )
|
1795
1814
|
@nendo.loadInitFile
|
1796
1815
|
end
|
1797
1816
|
it "should" do
|
@@ -1835,7 +1854,6 @@ EOS
|
|
1835
1854
|
EOS
|
1836
1855
|
).should == "()"
|
1837
1856
|
@nendo.evalStr( " (call-with-values * -) " ).should == "-1"
|
1838
|
-
@nendo.evalStr( " (receive (a) (values) (list a)) " ).should == "()"
|
1839
1857
|
@nendo.evalStr( " (receive (a) (values 10) (list a)) " ).should == "(10)"
|
1840
1858
|
@nendo.evalStr( " (receive (a b) (values 10 20) (list a b)) " ).should == "(10 20)"
|
1841
1859
|
@nendo.evalStr( " (receive (a b c) (values 10 20 30) (list a b c)) " ).should == "(10 20 30)"
|
@@ -1854,12 +1872,38 @@ EOS
|
|
1854
1872
|
@nendo.evalStr( " (receive (a b) (values nil #t) (cons a b)) " ).should == "(nil . #t)"
|
1855
1873
|
@nendo.evalStr( " (receive (a b) (values nil #f) (cons a b)) " ).should == "(nil . #f)"
|
1856
1874
|
@nendo.evalStr( " (receive (a b) (values nil nil) (cons a b)) " ).should == "(nil . nil)"
|
1875
|
+
lambda { @nendo.evalStr( " (receive (a) (values) (list a)) " ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
|
1876
|
+
lambda { @nendo.evalStr( <<EOS
|
1877
|
+
(map
|
1878
|
+
(lambda (a) a))
|
1879
|
+
EOS
|
1880
|
+
) }.should raise_error( ArgumentError, /wrong number of arguments/ )
|
1881
|
+
lambda { @nendo.evalStr( <<EOS
|
1882
|
+
(map
|
1883
|
+
(lambda () 1)
|
1884
|
+
'(1 2 3))
|
1885
|
+
EOS
|
1886
|
+
) }.should raise_error( ArgumentError, /wrong number of arguments/ )
|
1887
|
+
lambda { @nendo.evalStr( <<EOS
|
1888
|
+
(map
|
1889
|
+
(lambda (a) a)
|
1890
|
+
'(1 2 3)
|
1891
|
+
'(10 20 30))
|
1892
|
+
EOS
|
1893
|
+
) }.should raise_error( ArgumentError, /wrong number of arguments/ )
|
1894
|
+
lambda { @nendo.evalStr( <<EOS
|
1895
|
+
(map
|
1896
|
+
(lambda (a b) (+ a b))
|
1897
|
+
'(1 2 3))
|
1898
|
+
EOS
|
1899
|
+
) }.should raise_error( ArgumentError, /wrong number of arguments/ )
|
1857
1900
|
end
|
1858
1901
|
end
|
1859
1902
|
|
1860
1903
|
describe Nendo, "when toplevel variable was overwritten " do
|
1861
1904
|
before do
|
1862
1905
|
@nendo = Nendo::Core.new()
|
1906
|
+
@nendo.setDisplayErrors( false )
|
1863
1907
|
@nendo.loadInitFile
|
1864
1908
|
end
|
1865
1909
|
it "should" do
|
@@ -1992,7 +2036,7 @@ EOS
|
|
1992
2036
|
EOS
|
1993
2037
|
).should == "(define main (lambda (argv) (letrec ((result (quote ())) (foo (lambda (x) x)) (val 0) (bar (lambda (x) (+ val 10)))))))"
|
1994
2038
|
@nendo.evalStr( <<EOS
|
1995
|
-
(define (main argv)
|
2039
|
+
(define (main . argv)
|
1996
2040
|
(define (foo x) x)
|
1997
2041
|
(+ 10 20)
|
1998
2042
|
0
|
@@ -2073,6 +2117,7 @@ end
|
|
2073
2117
|
describe Nendo, "when use dot-operator (.) macro " do
|
2074
2118
|
before do
|
2075
2119
|
@nendo = Nendo::Core.new()
|
2120
|
+
@nendo.setDisplayErrors( false )
|
2076
2121
|
@nendo.loadInitFile
|
2077
2122
|
end
|
2078
2123
|
it "should" do
|
@@ -2092,8 +2137,7 @@ describe Nendo, "when use dot-operator (.) macro " do
|
|
2092
2137
|
@nendo.evalStr( " (to-s str.size) " ).should == '"6"'
|
2093
2138
|
@nendo.evalStr( " (to-s 'str.size) " ).should == '"str.size"'
|
2094
2139
|
@nendo.evalStr( " (require \"date\") " ).should == "#f"
|
2095
|
-
@nendo.evalStr( " (. (Date.new 0) strftime \"%
|
2096
|
-
@nendo.evalStr( " (. (Date.new 0) strftime \"%s\") " ).should == '"-62167392000"'
|
2140
|
+
@nendo.evalStr( " (. (Date.new 0) strftime \"%F %r\") " ).should == '"0000-01-01 12:00:00 AM"'
|
2097
2141
|
@nendo.evalStr( " (require \"digest/md5\") " ).should == "#f"
|
2098
2142
|
@nendo.evalStr( " (Digest::MD5.hexdigest \"abc\") " ).should == '"900150983cd24fb0d6963f7d28e17f72"'
|
2099
2143
|
@nendo.evalStr( " (Digest::MD5.hexdigest \"source text\") " ).should == '"20f79a1416626eeacc0bd9a8db87faa2"'
|
@@ -2147,6 +2191,7 @@ end
|
|
2147
2191
|
describe Nendo, "when use with-open libraries " do
|
2148
2192
|
before do
|
2149
2193
|
@nendo = Nendo::Core.new()
|
2194
|
+
@nendo.setDisplayErrors( false )
|
2150
2195
|
@nendo.loadInitFile
|
2151
2196
|
@fn = "/tmp/for-with-open.dat"
|
2152
2197
|
open( @fn, "w" ) { |f|
|
@@ -2159,6 +2204,7 @@ describe Nendo, "when use with-open libraries " do
|
|
2159
2204
|
@nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"line1"'
|
2160
2205
|
@nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"line1"'
|
2161
2206
|
@nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop) (f.readline.chop))) ", @fn )).should == '"line2"'
|
2207
|
+
@nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (map (lambda (line) (line.chop)) f))) ", @fn )).should == '#("line1" "line2" "line3")'
|
2162
2208
|
@nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.puts \"Wrote from Nendo.\")) \"w\") #t", @fn )).should == "#t"
|
2163
2209
|
@nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"Wrote from Nendo."'
|
2164
2210
|
lambda { @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) #t) 1 2 ", @fn )) }.should raise_error(RuntimeError)
|
@@ -2173,6 +2219,7 @@ end
|
|
2173
2219
|
describe Nendo, "when use (use ...) macro " do
|
2174
2220
|
before do
|
2175
2221
|
@nendo = Nendo::Core.new()
|
2222
|
+
@nendo.setDisplayErrors( false )
|
2176
2223
|
@nendo.loadInitFile
|
2177
2224
|
end
|
2178
2225
|
it "should" do
|
@@ -2194,6 +2241,7 @@ end
|
|
2194
2241
|
describe Nendo, "when use keyword feature " do
|
2195
2242
|
before do
|
2196
2243
|
@nendo = Nendo::Core.new()
|
2244
|
+
@nendo.setDisplayErrors( false )
|
2197
2245
|
@nendo.loadInitFile
|
2198
2246
|
end
|
2199
2247
|
it "should" do
|
@@ -2235,6 +2283,7 @@ end
|
|
2235
2283
|
describe Nendo, "when use hash-table feature " do
|
2236
2284
|
before do
|
2237
2285
|
@nendo = Nendo::Core.new()
|
2286
|
+
@nendo.setDisplayErrors( false )
|
2238
2287
|
@nendo.loadInitFile
|
2239
2288
|
end
|
2240
2289
|
it "should" do
|
@@ -2312,6 +2361,7 @@ end
|
|
2312
2361
|
describe Nendo, "when use vector feature " do
|
2313
2362
|
before do
|
2314
2363
|
@nendo = Nendo::Core.new()
|
2364
|
+
@nendo.setDisplayErrors( false )
|
2315
2365
|
@nendo.loadInitFile
|
2316
2366
|
end
|
2317
2367
|
it "should" do
|
@@ -2356,6 +2406,7 @@ end
|
|
2356
2406
|
describe Nendo, "tail call optimization " do
|
2357
2407
|
before do
|
2358
2408
|
@nendo = Nendo::Core.new()
|
2409
|
+
@nendo.setDisplayErrors( false )
|
2359
2410
|
@nendo.loadInitFile
|
2360
2411
|
@nendo.loadInitFile # to self optimizing. The init.nnd file will be loaded twice, so `filter' can be optimized on second loading phase.
|
2361
2412
|
end
|
@@ -2532,6 +2583,7 @@ end
|
|
2532
2583
|
describe Nendo, "When use :optional argument feature " do
|
2533
2584
|
before do
|
2534
2585
|
@nendo = Nendo::Core.new()
|
2586
|
+
@nendo.setDisplayErrors( false )
|
2535
2587
|
@nendo.loadInitFile
|
2536
2588
|
end
|
2537
2589
|
it "should" do
|
@@ -2555,6 +2607,7 @@ end
|
|
2555
2607
|
describe Nendo, "when use export-to-ruby macro " do
|
2556
2608
|
before do
|
2557
2609
|
@nendo = Nendo::Core.new()
|
2610
|
+
@nendo.setDisplayErrors( false )
|
2558
2611
|
@nendo.loadInitFile
|
2559
2612
|
end
|
2560
2613
|
it "should" do
|