nendo 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/test/nendo_spec.rb CHANGED
@@ -136,6 +136,18 @@ describe Nendo, "Ruby's lexical closure " do
136
136
  end
137
137
  end
138
138
 
139
+ describe Nendo, "Japanese characters in regex " do
140
+ before do
141
+ @matchData = "ABC漢字あいうえお漢字ABC".match( /([あ-ん])([あ-ん])([あ-ん])([あ-ん])([あ-ん])/ )
142
+ end
143
+ it "should" do
144
+ @matchData.should be_true
145
+ pending( "JRuby can't compute correctly" ) if defined? JRUBY_VERSION
146
+ @matchData[0].should == "あいうえお"
147
+ @matchData[1].should == "あ"
148
+ end
149
+ end
150
+
139
151
 
140
152
  describe Nendo, "Ruby's undefined instance variable " do
141
153
  it "should" do
@@ -146,7 +158,7 @@ end
146
158
 
147
159
  describe Evaluator, "When use Evaluator's util methods" do
148
160
  before do
149
- @evaluator = Evaluator.new()
161
+ @evaluator = Evaluator.new(Nendo::Core.new())
150
162
  end
151
163
  it "should" do
152
164
  @evaluator.toRubySymbol( "a" ).should == "_a"
@@ -201,290 +213,290 @@ describe Evaluator, "When use Evaluator's util methods" do
201
213
  end
202
214
  end
203
215
 
204
- describe Nendo, "when call replStr() with literals" do
216
+ describe Nendo, "when call evalStr() with literals" do
205
217
  before do
206
218
  @nendo = Nendo::Core.new()
207
219
  end
208
220
  it "should" do
209
- @nendo.replStr( " 1 " ).should == "1"
210
- @nendo.replStr( " 100000 " ).should == "100000"
211
- @nendo.replStr( " 1.1 " ).should == "1.1"
212
- @nendo.replStr( " 1.0 " ).should == "1.0"
213
- @nendo.replStr( ' "a" ' ).should == '"a"'
214
- @nendo.replStr( ' "日本語" ' ).should == '"日本語"'
215
- @nendo.replStr( ' "\n" ' ).should == "\"\n\""
216
- @nendo.replStr( ' "\r" ' ).should == "\"\\r\""
217
- @nendo.replStr( ' "\t" ' ).should == "\"\\t\""
218
- @nendo.replStr( ' "a" ' ).should == '"a"'
219
- @nendo.replStr( ' "a\"b" ' ).should == '"a\"b"'
220
- @nendo.replStr( ' "日\"本\"語" ' ).should == '"日\"本\"語"'
221
- @nendo.replStr( " true " ).should == "#t"
222
- @nendo.replStr( " false " ).should == "#f"
223
- @nendo.replStr( " nil " ).should == "nil"
224
- @nendo.replStr( " #t " ).should == "#t"
225
- @nendo.replStr( " #f " ).should == "#f"
221
+ @nendo.evalStr( " 1 " ).should == "1"
222
+ @nendo.evalStr( " 100000 " ).should == "100000"
223
+ @nendo.evalStr( " 1.1 " ).should == "1.1"
224
+ @nendo.evalStr( " 1.0 " ).should == "1.0"
225
+ @nendo.evalStr( ' "a" ' ).should == '"a"'
226
+ @nendo.evalStr( ' "日本語" ' ).should == '"日本語"'
227
+ @nendo.evalStr( ' "\n" ' ).should == "\"\n\""
228
+ @nendo.evalStr( ' "\r" ' ).should == "\"\\r\""
229
+ @nendo.evalStr( ' "\t" ' ).should == "\"\\t\""
230
+ @nendo.evalStr( ' "a" ' ).should == '"a"'
231
+ @nendo.evalStr( ' "a\"b" ' ).should == '"a\"b"'
232
+ @nendo.evalStr( ' "日\"本\"語" ' ).should == '"日\"本\"語"'
233
+ @nendo.evalStr( " true " ).should == "#t"
234
+ @nendo.evalStr( " false " ).should == "#f"
235
+ @nendo.evalStr( " nil " ).should == "nil"
236
+ @nendo.evalStr( " #t " ).should == "#t"
237
+ @nendo.evalStr( " #f " ).should == "#f"
226
238
 
227
239
  end
228
240
  end
229
241
 
230
- describe Nendo, "when call replStr() with comparative operators" do
242
+ describe Nendo, "when call evalStr() with comparative operators" do
231
243
  before do
232
244
  @nendo = Nendo::Core.new()
233
245
  end
234
246
  it "should" do
235
- @nendo.replStr( " (= 1 1) " ).should == "#t"
236
- @nendo.replStr( " (= 1 2) " ).should == "#f"
237
- @nendo.replStr( " (= #t #t) " ).should == "#t"
238
- @nendo.replStr( " (= #f #f) " ).should == "#t"
239
- @nendo.replStr( " (= true true) " ).should == "#t"
240
- @nendo.replStr( " (= false false) " ).should == "#t"
241
- @nendo.replStr( " (= #t true) " ).should == "#t"
242
- @nendo.replStr( " (= #f false) " ).should == "#t"
243
- @nendo.replStr( " (= #t #f) " ).should == "#f"
244
- @nendo.replStr( " (= true false) " ).should == "#f"
245
- @nendo.replStr( " (eq? 1 1) " ).should == "#t"
246
- @nendo.replStr( " (eq? 1 2) " ).should == "#f"
247
- @nendo.replStr( " (eq? 'a 'a) " ).should == "#t"
248
- @nendo.replStr( " (eq? 'b 'b) " ).should == "#t"
249
- @nendo.replStr( " (eq? 'a-b 'a-b) " ).should == "#t"
250
- @nendo.replStr( " (eq? 'a_b 'a-b) " ).should == "#f"
251
- @nendo.replStr( " (eq? 'a-b 'a_b) " ).should == "#f"
252
- @nendo.replStr( " (< 1 1) " ).should == "#f"
253
- @nendo.replStr( " (< 1 2) " ).should == "#t"
254
- @nendo.replStr( " (> 1 1) " ).should == "#f"
255
- @nendo.replStr( " (> 2 1) " ).should == "#t"
256
- @nendo.replStr( " (<= 1 0) " ).should == "#f"
257
- @nendo.replStr( " (<= 1 1) " ).should == "#t"
258
- @nendo.replStr( " (<= 1 2) " ).should == "#t"
259
- @nendo.replStr( " (>= 0 1) " ).should == "#f"
260
- @nendo.replStr( " (>= 1 1) " ).should == "#t"
261
- @nendo.replStr( " (equal? 1 1) " ).should == "#t"
262
- @nendo.replStr( " (equal? 1 2) " ).should == "#f"
263
- @nendo.replStr( " (equal? 2 2) " ).should == "#t"
264
- @nendo.replStr( " (equal? '() '()) " ).should == "#t"
265
- @nendo.replStr( " (equal? '(1) '(1)) " ).should == "#t"
266
- @nendo.replStr( " (equal? '(1) '(2)) " ).should == "#f"
267
- @nendo.replStr( " (equal? '(1 2 3) '(1 2 3)) " ).should == "#t"
268
- @nendo.replStr( " (equal? '(1 2 . 3) '(1 2 . 3)) " ).should == "#t"
269
- @nendo.replStr( " (equal? '(1 2 (3)) '(1 2 (3))) " ).should == "#t"
270
- @nendo.replStr( " (equal? '(1 2 (3)) '(1 2 (4))) " ).should == "#f"
271
- @nendo.replStr( " (equal? '(1 2 (3 (4))) '(1 2 (3 (4)))) " ).should == "#t"
272
- @nendo.replStr( " (equal? '((1) 2 3 4) '((2) 2 3 4)) " ).should == "#f"
273
- @nendo.replStr( " (equal? \"aaa\" \"aaa\") " ).should == "#t"
274
- @nendo.replStr( " (equal? \"aaa\" \"aax\") " ).should == "#f"
275
- @nendo.replStr( " (equal? '(\"aaa\") '(\"aaa\")) " ).should == "#t"
276
- @nendo.replStr( " (equal? '(\"aaa\" (1)) '(\"aaa\" (1))) " ).should == "#t"
277
- @nendo.replStr( " (equal? '(\"aaa\" (1)) '(\"aaa\" (2))) " ).should == "#f"
247
+ @nendo.evalStr( " (= 1 1) " ).should == "#t"
248
+ @nendo.evalStr( " (= 1 2) " ).should == "#f"
249
+ @nendo.evalStr( " (= #t #t) " ).should == "#t"
250
+ @nendo.evalStr( " (= #f #f) " ).should == "#t"
251
+ @nendo.evalStr( " (= true true) " ).should == "#t"
252
+ @nendo.evalStr( " (= false false) " ).should == "#t"
253
+ @nendo.evalStr( " (= #t true) " ).should == "#t"
254
+ @nendo.evalStr( " (= #f false) " ).should == "#t"
255
+ @nendo.evalStr( " (= #t #f) " ).should == "#f"
256
+ @nendo.evalStr( " (= true false) " ).should == "#f"
257
+ @nendo.evalStr( " (eq? 1 1) " ).should == "#t"
258
+ @nendo.evalStr( " (eq? 1 2) " ).should == "#f"
259
+ @nendo.evalStr( " (eq? 'a 'a) " ).should == "#t"
260
+ @nendo.evalStr( " (eq? 'b 'b) " ).should == "#t"
261
+ @nendo.evalStr( " (eq? 'a-b 'a-b) " ).should == "#t"
262
+ @nendo.evalStr( " (eq? 'a_b 'a-b) " ).should == "#f"
263
+ @nendo.evalStr( " (eq? 'a-b 'a_b) " ).should == "#f"
264
+ @nendo.evalStr( " (< 1 1) " ).should == "#f"
265
+ @nendo.evalStr( " (< 1 2) " ).should == "#t"
266
+ @nendo.evalStr( " (> 1 1) " ).should == "#f"
267
+ @nendo.evalStr( " (> 2 1) " ).should == "#t"
268
+ @nendo.evalStr( " (<= 1 0) " ).should == "#f"
269
+ @nendo.evalStr( " (<= 1 1) " ).should == "#t"
270
+ @nendo.evalStr( " (<= 1 2) " ).should == "#t"
271
+ @nendo.evalStr( " (>= 0 1) " ).should == "#f"
272
+ @nendo.evalStr( " (>= 1 1) " ).should == "#t"
273
+ @nendo.evalStr( " (equal? 1 1) " ).should == "#t"
274
+ @nendo.evalStr( " (equal? 1 2) " ).should == "#f"
275
+ @nendo.evalStr( " (equal? 2 2) " ).should == "#t"
276
+ @nendo.evalStr( " (equal? '() '()) " ).should == "#t"
277
+ @nendo.evalStr( " (equal? '(1) '(1)) " ).should == "#t"
278
+ @nendo.evalStr( " (equal? '(1) '(2)) " ).should == "#f"
279
+ @nendo.evalStr( " (equal? '(1 2 3) '(1 2 3)) " ).should == "#t"
280
+ @nendo.evalStr( " (equal? '(1 2 . 3) '(1 2 . 3)) " ).should == "#t"
281
+ @nendo.evalStr( " (equal? '(1 2 (3)) '(1 2 (3))) " ).should == "#t"
282
+ @nendo.evalStr( " (equal? '(1 2 (3)) '(1 2 (4))) " ).should == "#f"
283
+ @nendo.evalStr( " (equal? '(1 2 (3 (4))) '(1 2 (3 (4)))) " ).should == "#t"
284
+ @nendo.evalStr( " (equal? '((1) 2 3 4) '((2) 2 3 4)) " ).should == "#f"
285
+ @nendo.evalStr( " (equal? \"aaa\" \"aaa\") " ).should == "#t"
286
+ @nendo.evalStr( " (equal? \"aaa\" \"aax\") " ).should == "#f"
287
+ @nendo.evalStr( " (equal? '(\"aaa\") '(\"aaa\")) " ).should == "#t"
288
+ @nendo.evalStr( " (equal? '(\"aaa\" (1)) '(\"aaa\" (1))) " ).should == "#t"
289
+ @nendo.evalStr( " (equal? '(\"aaa\" (1)) '(\"aaa\" (2))) " ).should == "#f"
278
290
  end
279
291
  end
280
292
 
281
- describe Nendo, "when call replStr() with boolean operators" do
293
+ describe Nendo, "when call evalStr() with boolean operators" do
282
294
  before do
283
295
  @nendo = Nendo::Core.new()
284
296
  end
285
297
  it "should" do
286
- @nendo.replStr( " true " ).should == "#t"
287
- @nendo.replStr( " false " ).should == "#f"
288
- @nendo.replStr( " #t " ).should == "#t"
289
- @nendo.replStr( " #f " ).should == "#f"
290
- @nendo.replStr( " (not true) " ).should == "#f"
291
- @nendo.replStr( " (not #t) " ).should == "#f"
292
- @nendo.replStr( " (not 1) " ).should == "#f"
293
- @nendo.replStr( " (not false) " ).should == "#t"
294
- @nendo.replStr( " (not #f) " ).should == "#t"
295
- @nendo.replStr( " (not \"str\") " ).should == "#f"
296
- @nendo.replStr( " (not not) " ).should == "#f"
297
- @nendo.replStr( " (not (not true)) " ).should == "#t"
298
- @nendo.replStr( " (not (not #t)) " ).should == "#t"
299
- @nendo.replStr( " (not '()) " ).should == "#f"
300
- @nendo.replStr( " (not '(1)) " ).should == "#f"
298
+ @nendo.evalStr( " true " ).should == "#t"
299
+ @nendo.evalStr( " false " ).should == "#f"
300
+ @nendo.evalStr( " #t " ).should == "#t"
301
+ @nendo.evalStr( " #f " ).should == "#f"
302
+ @nendo.evalStr( " (not true) " ).should == "#f"
303
+ @nendo.evalStr( " (not #t) " ).should == "#f"
304
+ @nendo.evalStr( " (not 1) " ).should == "#f"
305
+ @nendo.evalStr( " (not false) " ).should == "#t"
306
+ @nendo.evalStr( " (not #f) " ).should == "#t"
307
+ @nendo.evalStr( " (not \"str\") " ).should == "#f"
308
+ @nendo.evalStr( " (not not) " ).should == "#f"
309
+ @nendo.evalStr( " (not (not true)) " ).should == "#t"
310
+ @nendo.evalStr( " (not (not #t)) " ).should == "#t"
311
+ @nendo.evalStr( " (not '()) " ).should == "#f"
312
+ @nendo.evalStr( " (not '(1)) " ).should == "#f"
301
313
  end
302
314
  end
303
315
 
304
- describe Nendo, "when call replStr() with `+' function" do
316
+ describe Nendo, "when call evalStr() with `+' function" do
305
317
  before do
306
318
  @nendo = Nendo::Core.new()
307
319
  end
308
320
  it "should" do
309
- @nendo.replStr( " (+ 1) " ).should == "1"
310
- @nendo.replStr( " (+ 1 1) " ).should == "2"
311
- @nendo.replStr( " (+ 1 1 1 1 1 1 1 1 1 1) " ).should == "10"
312
- @nendo.replStr( " (+ 1 2 3 4 5) " ).should == "15"
313
- @nendo.replStr( " (+ 1 (+ 2 (+ 3 (+ 4 (+ 5))))) " ).should == "15"
314
- @nendo.replStr( " (+ 1 1.1) " ).should == "2.1"
315
- @nendo.replStr( " (+ 1.1 1.2) " ).should == "2.3"
316
- @nendo.replStr( " (+ \"a\" ) " ).should == '"a"'
317
- @nendo.replStr( " (+ \"a\" \"B\" \"c\" ) " ).should == '"aBc"'
318
- @nendo.replStr( " (+) " ).should == "0"
319
- lambda { @nendo.replStr( " (+ '() ) " ) }.should raise_error(TypeError)
320
- lambda { @nendo.replStr( " (+ 1 '() ) " ) }.should raise_error(TypeError)
321
- lambda { @nendo.replStr( " (+ 1.1 '() ) " ) }.should raise_error(TypeError)
322
- lambda { @nendo.replStr( " (+ '(1) ) " ) }.should raise_error(TypeError)
323
- lambda { @nendo.replStr( " (+ 1.1 \"a\" ) " ) }.should raise_error(TypeError)
324
- lambda { @nendo.replStr( " (+ \"a\" 1) " ) }.should raise_error(TypeError)
325
- lambda { @nendo.replStr( " (+ \"a\" 1.1) " ) }.should raise_error(TypeError)
321
+ @nendo.evalStr( " (+ 1) " ).should == "1"
322
+ @nendo.evalStr( " (+ 1 1) " ).should == "2"
323
+ @nendo.evalStr( " (+ 1 1 1 1 1 1 1 1 1 1) " ).should == "10"
324
+ @nendo.evalStr( " (+ 1 2 3 4 5) " ).should == "15"
325
+ @nendo.evalStr( " (+ 1 (+ 2 (+ 3 (+ 4 (+ 5))))) " ).should == "15"
326
+ @nendo.evalStr( " (+ 1 1.1) " ).should == "2.1"
327
+ @nendo.evalStr( " (+ 1.1 1.2) " ).should == "2.3"
328
+ @nendo.evalStr( " (+ \"a\" ) " ).should == '"a"'
329
+ @nendo.evalStr( " (+ \"a\" \"B\" \"c\" ) " ).should == '"aBc"'
330
+ @nendo.evalStr( " (+) " ).should == "0"
331
+ lambda { @nendo.evalStr( " (+ '() ) " ) }.should raise_error(TypeError)
332
+ lambda { @nendo.evalStr( " (+ 1 '() ) " ) }.should raise_error(TypeError)
333
+ lambda { @nendo.evalStr( " (+ 1.1 '() ) " ) }.should raise_error(TypeError)
334
+ lambda { @nendo.evalStr( " (+ '(1) ) " ) }.should raise_error(TypeError)
335
+ lambda { @nendo.evalStr( " (+ 1.1 \"a\" ) " ) }.should raise_error(TypeError)
336
+ lambda { @nendo.evalStr( " (+ \"a\" 1) " ) }.should raise_error(TypeError)
337
+ lambda { @nendo.evalStr( " (+ \"a\" 1.1) " ) }.should raise_error(TypeError)
326
338
  end
327
339
  end
328
340
 
329
- describe Nendo, "when call replStr() with `-' function" do
341
+ describe Nendo, "when call evalStr() with `-' function" do
330
342
  before do
331
343
  @nendo = Nendo::Core.new()
332
344
  end
333
345
  it "should" do
334
- @nendo.replStr( " (- 1) " ).should == "-1"
335
- @nendo.replStr( " (- 2 1) " ).should == "1"
336
- @nendo.replStr( " (- 2 5) " ).should == "-3"
337
- @nendo.replStr( " (- 100 1 1 1 1 1 1 1 1 1 1) " ).should == "90"
338
- @nendo.replStr( " (- 100 (- 10 3)) " ).should == "93"
339
- @nendo.replStr( " (- 1.1 1) " ).should == (1.1-1).to_s
340
- @nendo.replStr( " (- 1.3 1.1) " ).should == (1.3-1.1).to_s
341
- lambda { @nendo.replStr( " (- 1 '() ) " ) }.should raise_error(TypeError)
342
- lambda { @nendo.replStr( " (- 1.1 '() ) " ) }.should raise_error(TypeError)
343
- lambda { @nendo.replStr( " (-) " ) }.should raise_error(ArgumentError)
344
- lambda { @nendo.replStr( " (- '(1) ) " ) }.should raise_error(TypeError)
345
- lambda { @nendo.replStr( " (- '() ) " ) }.should raise_error(TypeError)
346
- lambda { @nendo.replStr( " (- 1.1 \"a\" ) " ) }.should raise_error(TypeError)
346
+ @nendo.evalStr( " (- 1) " ).should == "-1"
347
+ @nendo.evalStr( " (- 2 1) " ).should == "1"
348
+ @nendo.evalStr( " (- 2 5) " ).should == "-3"
349
+ @nendo.evalStr( " (- 100 1 1 1 1 1 1 1 1 1 1) " ).should == "90"
350
+ @nendo.evalStr( " (- 100 (- 10 3)) " ).should == "93"
351
+ @nendo.evalStr( " (- 1.1 1) " ).should == (1.1-1).to_s
352
+ @nendo.evalStr( " (- 1.3 1.1) " ).should == (1.3-1.1).to_s
353
+ lambda { @nendo.evalStr( " (- 1 '() ) " ) }.should raise_error(TypeError)
354
+ lambda { @nendo.evalStr( " (- 1.1 '() ) " ) }.should raise_error(TypeError)
355
+ lambda { @nendo.evalStr( " (-) " ) }.should raise_error(ArgumentError)
356
+ lambda { @nendo.evalStr( " (- '(1) ) " ) }.should raise_error(TypeError)
357
+ lambda { @nendo.evalStr( " (- '() ) " ) }.should raise_error(TypeError)
358
+ lambda { @nendo.evalStr( " (- 1.1 \"a\" ) " ) }.should raise_error(TypeError)
347
359
  end
348
360
  end
349
361
 
350
- describe Nendo, "when call replStr() with `*' function" do
362
+ describe Nendo, "when call evalStr() with `*' function" do
351
363
  before do
352
364
  @nendo = Nendo::Core.new()
353
365
  end
354
366
  it "should" do
355
- @nendo.replStr( " (* 1) " ).should == "1"
356
- @nendo.replStr( " (* 2 1) " ).should == "2"
357
- @nendo.replStr( " (* 2 5) " ).should == "10"
358
- @nendo.replStr( " (* 1 2 3 4 5 6 7 8 9 10) " ).should == "3628800"
359
- @nendo.replStr( " (* 100 (* 10 10 10)) " ).should == "100000"
360
- @nendo.replStr( " (* 1.1 1) " ).should == "1.1"
361
- @nendo.replStr( " (* 1.3 1.1) " ).should == (1.3*1.1).to_s
362
- @nendo.replStr( " (*) " ).should == "1"
363
- lambda { @nendo.replStr( " (* '() ) " ) }.should raise_error(TypeError)
364
- lambda { @nendo.replStr( " (* 1 '() ) " ) }.should raise_error(TypeError)
365
- lambda { @nendo.replStr( " (* 1.1 '() ) " ) }.should raise_error(TypeError)
366
- lambda { @nendo.replStr( " (* '(1) ) " ) }.should raise_error(TypeError)
367
- lambda { @nendo.replStr( " (* 1.1 \"a\" ) " ) }.should raise_error(TypeError)
368
- lambda { @nendo.replStr( " (* \"a\" 1) " ) }.should raise_error(TypeError)
369
- lambda { @nendo.replStr( " (* \"a\" 1.1) " ) }.should raise_error(TypeError)
367
+ @nendo.evalStr( " (* 1) " ).should == "1"
368
+ @nendo.evalStr( " (* 2 1) " ).should == "2"
369
+ @nendo.evalStr( " (* 2 5) " ).should == "10"
370
+ @nendo.evalStr( " (* 1 2 3 4 5 6 7 8 9 10) " ).should == "3628800"
371
+ @nendo.evalStr( " (* 100 (* 10 10 10)) " ).should == "100000"
372
+ @nendo.evalStr( " (* 1.1 1) " ).should == "1.1"
373
+ @nendo.evalStr( " (* 1.3 1.1) " ).should == (1.3*1.1).to_s
374
+ @nendo.evalStr( " (*) " ).should == "1"
375
+ lambda { @nendo.evalStr( " (* '() ) " ) }.should raise_error(TypeError)
376
+ lambda { @nendo.evalStr( " (* 1 '() ) " ) }.should raise_error(TypeError)
377
+ lambda { @nendo.evalStr( " (* 1.1 '() ) " ) }.should raise_error(TypeError)
378
+ lambda { @nendo.evalStr( " (* '(1) ) " ) }.should raise_error(TypeError)
379
+ lambda { @nendo.evalStr( " (* 1.1 \"a\" ) " ) }.should raise_error(TypeError)
380
+ lambda { @nendo.evalStr( " (* \"a\" 1) " ) }.should raise_error(TypeError)
381
+ lambda { @nendo.evalStr( " (* \"a\" 1.1) " ) }.should raise_error(TypeError)
370
382
  end
371
383
  end
372
384
 
373
- describe Nendo, "when call replStr() with `/' function" do
385
+ describe Nendo, "when call evalStr() with `/' function" do
374
386
  before do
375
387
  @nendo = Nendo::Core.new()
376
388
  end
377
389
  it "should" do
378
- @nendo.replStr( " (/ 1) " ).should == "1"
379
- @nendo.replStr( " (/ 1.1) " ).should ==
390
+ @nendo.evalStr( " (/ 1) " ).should == "1"
391
+ @nendo.evalStr( " (/ 1.1) " ).should ==
380
392
  (1/1.1).to_s
381
- @nendo.replStr( " (/ 2 1) " ).should == "2"
382
- @nendo.replStr( " (/ 2 2) " ).should == "1"
383
- @nendo.replStr( " (/ 2 2.0) " ).should == "1.0"
384
- @nendo.replStr( " (/ 2 5.0) " ).should == "0.4"
385
- @nendo.replStr( " (/ 10.0 2 2 2 2 2 2 2 2 2 2) " ).should == "0.009765625"
386
- @nendo.replStr( " (/ 100 (/ 100 10) 10) " ).should == "1"
387
- @nendo.replStr( " (/ 1 1.11) " ).should ==
393
+ @nendo.evalStr( " (/ 2 1) " ).should == "2"
394
+ @nendo.evalStr( " (/ 2 2) " ).should == "1"
395
+ @nendo.evalStr( " (/ 2 2.0) " ).should == "1.0"
396
+ @nendo.evalStr( " (/ 2 5.0) " ).should == "0.4"
397
+ @nendo.evalStr( " (/ 10.0 2 2 2 2 2 2 2 2 2 2) " ).should == "0.009765625"
398
+ @nendo.evalStr( " (/ 100 (/ 100 10) 10) " ).should == "1"
399
+ @nendo.evalStr( " (/ 1 1.11) " ).should ==
388
400
  (1/1.11).to_s
389
- @nendo.replStr( " (/ 1.3 1.1) " ).should ==
401
+ @nendo.evalStr( " (/ 1.3 1.1) " ).should ==
390
402
  (1.3/1.1).to_s
391
- lambda { @nendo.replStr( " (/ 1 '() ) " ) }.should raise_error(TypeError)
392
- lambda { @nendo.replStr( " (/ 1.1 '() ) " ) }.should raise_error(TypeError)
393
- lambda { @nendo.replStr( " (/) " ) }.should raise_error(ArgumentError)
394
- lambda { @nendo.replStr( " (/ '() ) " ) }.should raise_error(TypeError)
395
- lambda { @nendo.replStr( " (/ 1.1 \"a\" ) " ) }.should raise_error(TypeError)
403
+ lambda { @nendo.evalStr( " (/ 1 '() ) " ) }.should raise_error(TypeError)
404
+ lambda { @nendo.evalStr( " (/ 1.1 '() ) " ) }.should raise_error(TypeError)
405
+ lambda { @nendo.evalStr( " (/) " ) }.should raise_error(ArgumentError)
406
+ lambda { @nendo.evalStr( " (/ '() ) " ) }.should raise_error(TypeError)
407
+ lambda { @nendo.evalStr( " (/ 1.1 \"a\" ) " ) }.should raise_error(TypeError)
396
408
  end
397
409
  end
398
410
 
399
- describe Nendo, "when call replStr() with `%' function" do
411
+ describe Nendo, "when call evalStr() with `%' function" do
400
412
  before do
401
413
  @nendo = Nendo::Core.new()
402
414
  end
403
415
  it "should" do
404
- @nendo.replStr( " (% 1) " ).should == "0"
405
- @nendo.replStr( " (% 1.1) " ).should == "1.0"
406
- @nendo.replStr( " (% 2 1) " ).should == "0"
407
- @nendo.replStr( " (% 2 2) " ).should == "0"
408
- @nendo.replStr( " (% 2 2.0) " ).should == "0.0"
409
- @nendo.replStr( " (% 2 5.0) " ).should == "2.0"
410
- @nendo.replStr( " (% 100 (% 103 10)) " ).should == "1"
411
- @nendo.replStr( " (% 1 1.11) " ).should == "1.0"
412
- @nendo.replStr( " (% 1.3 1.1) " ).should == (1.3%1.1).to_s
413
- lambda { @nendo.replStr( " (% 1 '() ) " ) }.should raise_error(TypeError)
414
- lambda { @nendo.replStr( " (% 1.1 '() ) " ) }.should raise_error(TypeError)
415
- lambda { @nendo.replStr( " (\%) " ) }.should raise_error(ArgumentError)
416
- lambda { @nendo.replStr( " (\% '() ) " ) }.should raise_error(TypeError)
417
- lambda { @nendo.replStr( " (\% 1.1 \"a\" ) " ) }.should raise_error(TypeError)
416
+ @nendo.evalStr( " (% 1) " ).should == "0"
417
+ @nendo.evalStr( " (% 1.1) " ).should == "1.0"
418
+ @nendo.evalStr( " (% 2 1) " ).should == "0"
419
+ @nendo.evalStr( " (% 2 2) " ).should == "0"
420
+ @nendo.evalStr( " (% 2 2.0) " ).should == "0.0"
421
+ @nendo.evalStr( " (% 2 5.0) " ).should == "2.0"
422
+ @nendo.evalStr( " (% 100 (% 103 10)) " ).should == "1"
423
+ @nendo.evalStr( " (% 1 1.11) " ).should == "1.0"
424
+ @nendo.evalStr( " (% 1.3 1.1) " ).should == (1.3%1.1).to_s
425
+ lambda { @nendo.evalStr( " (% 1 '() ) " ) }.should raise_error(TypeError)
426
+ lambda { @nendo.evalStr( " (% 1.1 '() ) " ) }.should raise_error(TypeError)
427
+ lambda { @nendo.evalStr( " (\%) " ) }.should raise_error(ArgumentError)
428
+ lambda { @nendo.evalStr( " (\% '() ) " ) }.should raise_error(TypeError)
429
+ lambda { @nendo.evalStr( " (\% 1.1 \"a\" ) " ) }.should raise_error(TypeError)
418
430
  end
419
431
  end
420
432
 
421
- describe Nendo, "when call replStr() with `quotient' function" do
433
+ describe Nendo, "when call evalStr() with `quotient' function" do
422
434
  before do
423
435
  @nendo = Nendo::Core.new()
424
436
  end
425
437
  it "should" do
426
- @nendo.replStr( " (quotient 2 1) " ).should == "2"
427
- @nendo.replStr( " (quotient 2 2) " ).should == "1"
428
- @nendo.replStr( " (quotient 2 2.0) " ).should == "1"
429
- @nendo.replStr( " (quotient 2 5.0) " ).should == "0"
430
- @nendo.replStr( " (quotient 1 1.11) " ).should == "0"
431
- @nendo.replStr( " (quotient 10 3) " ).should == "3"
432
- @nendo.replStr( " (quotient -10 3) " ).should == "-3"
433
- @nendo.replStr( " (quotient 10 -3) " ).should == "-3"
434
- @nendo.replStr( " (quotient 10 -2) " ).should == "-5"
435
- lambda { @nendo.replStr( " (quotient 1 ) " ) }.should raise_error(ArgumentError)
436
- lambda { @nendo.replStr( " (quotient 1.1 ) " ) }.should raise_error(ArgumentError)
437
- lambda { @nendo.replStr( " (quotient) " ) }.should raise_error(ArgumentError)
438
- lambda { @nendo.replStr( " (quotient '() ) " ) }.should raise_error(ArgumentError)
439
- lambda { @nendo.replStr( " (quotient 1.1 \"a\" ) " ) }.should raise_error(TypeError)
440
- lambda { @nendo.replStr( " (quotient \"a\" 1.1 ) " ) }.should raise_error(TypeError)
438
+ @nendo.evalStr( " (quotient 2 1) " ).should == "2"
439
+ @nendo.evalStr( " (quotient 2 2) " ).should == "1"
440
+ @nendo.evalStr( " (quotient 2 2.0) " ).should == "1"
441
+ @nendo.evalStr( " (quotient 2 5.0) " ).should == "0"
442
+ @nendo.evalStr( " (quotient 1 1.11) " ).should == "0"
443
+ @nendo.evalStr( " (quotient 10 3) " ).should == "3"
444
+ @nendo.evalStr( " (quotient -10 3) " ).should == "-3"
445
+ @nendo.evalStr( " (quotient 10 -3) " ).should == "-3"
446
+ @nendo.evalStr( " (quotient 10 -2) " ).should == "-5"
447
+ lambda { @nendo.evalStr( " (quotient 1 ) " ) }.should raise_error(ArgumentError)
448
+ lambda { @nendo.evalStr( " (quotient 1.1 ) " ) }.should raise_error(ArgumentError)
449
+ lambda { @nendo.evalStr( " (quotient) " ) }.should raise_error(ArgumentError)
450
+ lambda { @nendo.evalStr( " (quotient '() ) " ) }.should raise_error(ArgumentError)
451
+ lambda { @nendo.evalStr( " (quotient 1.1 \"a\" ) " ) }.should raise_error(TypeError)
452
+ lambda { @nendo.evalStr( " (quotient \"a\" 1.1 ) " ) }.should raise_error(TypeError)
441
453
  end
442
454
  end
443
455
 
444
- describe Nendo, "when call replStr() with `remainder' function" do
456
+ describe Nendo, "when call evalStr() with `remainder' function" do
445
457
  before do
446
458
  @nendo = Nendo::Core.new()
447
459
  end
448
460
  it "should" do
449
- @nendo.replStr( " (remainder 2 1) " ).should == "0"
450
- @nendo.replStr( " (remainder 2 2) " ).should == "0"
451
- @nendo.replStr( " (remainder 2 2.0) " ).should == "0.0"
452
- @nendo.replStr( " (remainder 2 5.0) " ).should == "2.0"
453
- @nendo.replStr( " (remainder 1 1.11) " ).should == "1.0"
454
- @nendo.replStr( " (remainder 10 3) " ).should == "1"
455
- @nendo.replStr( " (remainder -10 3) " ).should == "-1"
456
- @nendo.replStr( " (remainder 10 -3) " ).should == "1"
457
- @nendo.replStr( " (remainder -10 -3) " ).should == "-1"
458
- @nendo.replStr( " (remainder 10 -2) " ).should == "0"
459
- lambda { @nendo.replStr( " (remainder 1 '() ) " ) }.should raise_error(TypeError)
460
- lambda { @nendo.replStr( " (remainder 1.1 '() ) " ) }.should raise_error(TypeError)
461
- lambda { @nendo.replStr( " (remainder) " ) }.should raise_error(ArgumentError)
462
- lambda { @nendo.replStr( " (remainder '() ) " ) }.should raise_error(ArgumentError)
463
- lambda { @nendo.replStr( " (remainder 1.1 \"a\" ) " ) }.should raise_error(TypeError)
461
+ @nendo.evalStr( " (remainder 2 1) " ).should == "0"
462
+ @nendo.evalStr( " (remainder 2 2) " ).should == "0"
463
+ @nendo.evalStr( " (remainder 2 2.0) " ).should == "0.0"
464
+ @nendo.evalStr( " (remainder 2 5.0) " ).should == "2.0"
465
+ @nendo.evalStr( " (remainder 1 1.11) " ).should == "1.0"
466
+ @nendo.evalStr( " (remainder 10 3) " ).should == "1"
467
+ @nendo.evalStr( " (remainder -10 3) " ).should == "-1"
468
+ @nendo.evalStr( " (remainder 10 -3) " ).should == "1"
469
+ @nendo.evalStr( " (remainder -10 -3) " ).should == "-1"
470
+ @nendo.evalStr( " (remainder 10 -2) " ).should == "0"
471
+ lambda { @nendo.evalStr( " (remainder 1 '() ) " ) }.should raise_error(TypeError)
472
+ lambda { @nendo.evalStr( " (remainder 1.1 '() ) " ) }.should raise_error(TypeError)
473
+ lambda { @nendo.evalStr( " (remainder) " ) }.should raise_error(ArgumentError)
474
+ lambda { @nendo.evalStr( " (remainder '() ) " ) }.should raise_error(ArgumentError)
475
+ lambda { @nendo.evalStr( " (remainder 1.1 \"a\" ) " ) }.should raise_error(TypeError)
464
476
  end
465
477
  end
466
478
 
467
- describe Nendo, "when call replStr() with `modulo' function" do
479
+ describe Nendo, "when call evalStr() with `modulo' function" do
468
480
  before do
469
481
  @nendo = Nendo::Core.new()
470
482
  end
471
483
  it "should" do
472
- @nendo.replStr( " (modulo 2 1) " ).should == "0"
473
- @nendo.replStr( " (modulo 2 2) " ).should == "0"
474
- @nendo.replStr( " (modulo 2 2.0) " ).should == "0.0"
475
- @nendo.replStr( " (modulo 2 5.0) " ).should == "2.0"
476
- @nendo.replStr( " (modulo 100 (modulo 103 10)) " ).should == "1"
477
- @nendo.replStr( " (modulo 1 1.11) " ).should == "1.0"
478
- @nendo.replStr( " (modulo 10 3) " ).should == "1"
479
- @nendo.replStr( " (modulo -10 3) " ).should == "2"
480
- @nendo.replStr( " (modulo 10 -3) " ).should == "-2"
481
- @nendo.replStr( " (modulo -10 -3) " ).should == "-1"
482
- @nendo.replStr( " (modulo 10 -2) " ).should == "0"
483
- lambda { @nendo.replStr( " (modulo 1 '() ) " ) }.should raise_error(TypeError)
484
- lambda { @nendo.replStr( " (modulo 1.1 '() ) " ) }.should raise_error(TypeError)
485
- lambda { @nendo.replStr( " (modulo) " ) }.should raise_error(ArgumentError)
486
- lambda { @nendo.replStr( " (modulo '() ) " ) }.should raise_error(TypeError)
487
- lambda { @nendo.replStr( " (modulo 1.1 \"a\" ) " ) }.should raise_error(TypeError)
484
+ @nendo.evalStr( " (modulo 2 1) " ).should == "0"
485
+ @nendo.evalStr( " (modulo 2 2) " ).should == "0"
486
+ @nendo.evalStr( " (modulo 2 2.0) " ).should == "0.0"
487
+ @nendo.evalStr( " (modulo 2 5.0) " ).should == "2.0"
488
+ @nendo.evalStr( " (modulo 100 (modulo 103 10)) " ).should == "1"
489
+ @nendo.evalStr( " (modulo 1 1.11) " ).should == "1.0"
490
+ @nendo.evalStr( " (modulo 10 3) " ).should == "1"
491
+ @nendo.evalStr( " (modulo -10 3) " ).should == "2"
492
+ @nendo.evalStr( " (modulo 10 -3) " ).should == "-2"
493
+ @nendo.evalStr( " (modulo -10 -3) " ).should == "-1"
494
+ @nendo.evalStr( " (modulo 10 -2) " ).should == "0"
495
+ lambda { @nendo.evalStr( " (modulo 1 '() ) " ) }.should raise_error(TypeError)
496
+ lambda { @nendo.evalStr( " (modulo 1.1 '() ) " ) }.should raise_error(TypeError)
497
+ lambda { @nendo.evalStr( " (modulo) " ) }.should raise_error(ArgumentError)
498
+ lambda { @nendo.evalStr( " (modulo '() ) " ) }.should raise_error(TypeError)
499
+ lambda { @nendo.evalStr( " (modulo 1.1 \"a\" ) " ) }.should raise_error(TypeError)
488
500
  end
489
501
  end
490
502
 
@@ -493,50 +505,50 @@ describe Nendo, "when read various list expressions" do
493
505
  @nendo = Nendo::Core.new()
494
506
  end
495
507
  it "should" do
496
- @nendo.replStr( " '() " ).should == "()"
497
- @nendo.replStr( " '[] " ).should == "()"
498
- @nendo.replStr( " '(1 . 1) " ).should == "(1 . 1)"
499
- @nendo.replStr( " '[1 . 1) " ).should == "(1 . 1)"
500
- @nendo.replStr( " '(1 . 1] " ).should == "(1 . 1)"
501
- @nendo.replStr( " '(1 1 . 1) " ).should == "(1 1 . 1)"
502
- @nendo.replStr( " '(1 2 . 3) " ).should == "(1 2 . 3)"
503
- @nendo.replStr( " '(1 2 3) " ).should == "(1 2 3)"
504
- @nendo.replStr( " '(1.1 2.2 3.3) " ).should == "(1.1 2.2 3.3)"
505
- @nendo.replStr( " '(a bb ccc dddd) " ).should == "(a bb ccc dddd)"
506
- @nendo.replStr( " '(a (b) ((c)) (((d)))) " ).should == "(a (b) ((c)) (((d))))"
507
- @nendo.replStr( " '[a (b) ((c)) (((d)))] " ).should == "(a (b) ((c)) (((d))))"
508
- @nendo.replStr( " '(a [b] ([c]) (([d]))) " ).should == "(a (b) ((c)) (((d))))"
509
- @nendo.replStr( " '[a [b] [[c]] [[[d]]]] " ).should == "(a (b) ((c)) (((d))))"
510
- @nendo.replStr( " '('a)" ).should == "('a)"
511
- @nendo.replStr( " '(''a)" ).should == "(''a)"
512
- @nendo.replStr( " '('a 'b 'c)" ).should == "('a 'b 'c)"
513
- @nendo.replStr( ' \'("str") ' ).should == '("str")'
514
- @nendo.replStr( ' \'("str" . 1) ' ).should == '("str" . 1)'
515
- @nendo.replStr( ' \'(1 . "str") ' ).should == '(1 . "str")'
516
- @nendo.replStr( ' \'(1 2 . "str") ' ).should == '(1 2 . "str")'
517
- @nendo.replStr( " '((a)(b)(c)) " ).should == "((a) (b) (c))"
518
- @nendo.replStr( " 'a " ).should == "a"
519
- @nendo.replStr( " 'symbol " ).should == "symbol"
520
- @nendo.replStr( " 'SYMBOL " ).should == "SYMBOL"
521
- @nendo.replStr( " 'SyMbOl " ).should == "SyMbOl"
522
- @nendo.replStr( " ''a " ).should == "'a"
523
- @nendo.replStr( " '1 " ).should == "1"
524
- @nendo.replStr( " ''1 " ).should == "'1"
525
- @nendo.replStr( " '''1 " ).should == "''1"
526
- @nendo.replStr( " '1.1 " ).should == "1.1"
527
- @nendo.replStr( " ''1.1 " ).should == "'1.1"
528
- @nendo.replStr( " '''1.1 " ).should == "''1.1"
529
- @nendo.replStr( " '() " ).should == "()"
530
- @nendo.replStr( " '(()) " ).should == "(())"
531
- @nendo.replStr( " '((())) " ).should == "((()))"
532
- @nendo.replStr( " '(((()))) " ).should == "(((())))"
533
- @nendo.replStr( " '(() . ()) " ).should == "(())"
534
- @nendo.replStr( " '(a . ()) " ).should == "(a)"
535
- @nendo.replStr( " '(a . #t) " ).should == "(a . #t)"
536
- @nendo.replStr( " '(a . #f) " ).should == "(a . #f)"
537
- @nendo.replStr( " '(a . nil) " ).should == "(a . nil)"
538
- @nendo.replStr( " '(a b c d e . ()) " ).should == "(a b c d e)"
539
- @nendo.replStr( " '(#t #t #f #f nil nil '() '()) " ).should == "(#t #t #f #f nil nil '() '())"
508
+ @nendo.evalStr( " '() " ).should == "()"
509
+ @nendo.evalStr( " '[] " ).should == "()"
510
+ @nendo.evalStr( " '(1 . 1) " ).should == "(1 . 1)"
511
+ @nendo.evalStr( " '[1 . 1) " ).should == "(1 . 1)"
512
+ @nendo.evalStr( " '(1 . 1] " ).should == "(1 . 1)"
513
+ @nendo.evalStr( " '(1 1 . 1) " ).should == "(1 1 . 1)"
514
+ @nendo.evalStr( " '(1 2 . 3) " ).should == "(1 2 . 3)"
515
+ @nendo.evalStr( " '(1 2 3) " ).should == "(1 2 3)"
516
+ @nendo.evalStr( " '(1.1 2.2 3.3) " ).should == "(1.1 2.2 3.3)"
517
+ @nendo.evalStr( " '(a bb ccc dddd) " ).should == "(a bb ccc dddd)"
518
+ @nendo.evalStr( " '(a (b) ((c)) (((d)))) " ).should == "(a (b) ((c)) (((d))))"
519
+ @nendo.evalStr( " '[a (b) ((c)) (((d)))] " ).should == "(a (b) ((c)) (((d))))"
520
+ @nendo.evalStr( " '(a [b] ([c]) (([d]))) " ).should == "(a (b) ((c)) (((d))))"
521
+ @nendo.evalStr( " '[a [b] [[c]] [[[d]]]] " ).should == "(a (b) ((c)) (((d))))"
522
+ @nendo.evalStr( " '('a)" ).should == "('a)"
523
+ @nendo.evalStr( " '(''a)" ).should == "(''a)"
524
+ @nendo.evalStr( " '('a 'b 'c)" ).should == "('a 'b 'c)"
525
+ @nendo.evalStr( ' \'("str") ' ).should == '("str")'
526
+ @nendo.evalStr( ' \'("str" . 1) ' ).should == '("str" . 1)'
527
+ @nendo.evalStr( ' \'(1 . "str") ' ).should == '(1 . "str")'
528
+ @nendo.evalStr( ' \'(1 2 . "str") ' ).should == '(1 2 . "str")'
529
+ @nendo.evalStr( " '((a)(b)(c)) " ).should == "((a) (b) (c))"
530
+ @nendo.evalStr( " 'a " ).should == "a"
531
+ @nendo.evalStr( " 'symbol " ).should == "symbol"
532
+ @nendo.evalStr( " 'SYMBOL " ).should == "SYMBOL"
533
+ @nendo.evalStr( " 'SyMbOl " ).should == "SyMbOl"
534
+ @nendo.evalStr( " ''a " ).should == "'a"
535
+ @nendo.evalStr( " '1 " ).should == "1"
536
+ @nendo.evalStr( " ''1 " ).should == "'1"
537
+ @nendo.evalStr( " '''1 " ).should == "''1"
538
+ @nendo.evalStr( " '1.1 " ).should == "1.1"
539
+ @nendo.evalStr( " ''1.1 " ).should == "'1.1"
540
+ @nendo.evalStr( " '''1.1 " ).should == "''1.1"
541
+ @nendo.evalStr( " '() " ).should == "()"
542
+ @nendo.evalStr( " '(()) " ).should == "(())"
543
+ @nendo.evalStr( " '((())) " ).should == "((()))"
544
+ @nendo.evalStr( " '(((()))) " ).should == "(((())))"
545
+ @nendo.evalStr( " '(() . ()) " ).should == "(())"
546
+ @nendo.evalStr( " '(a . ()) " ).should == "(a)"
547
+ @nendo.evalStr( " '(a . #t) " ).should == "(a . #t)"
548
+ @nendo.evalStr( " '(a . #f) " ).should == "(a . #f)"
549
+ @nendo.evalStr( " '(a . nil) " ).should == "(a . nil)"
550
+ @nendo.evalStr( " '(a b c d e . ()) " ).should == "(a b c d e)"
551
+ @nendo.evalStr( " '(#t #t #f #f nil nil '() '()) " ).should == "(#t #t #f #f nil nil '() '())"
540
552
  end
541
553
  end
542
554
 
@@ -547,66 +559,174 @@ describe Nendo, "when use #xxxx syntax " do
547
559
  @nendo.loadInitFile
548
560
  end
549
561
  it "should" do
550
- @nendo.replStr( " #t " ).should == "#t"
551
- @nendo.replStr( " #f " ).should == "#f"
552
- @nendo.replStr( " '#( 1 ) " ).should == "#(1)"
553
- @nendo.replStr( " '#() " ).should == "#()"
554
- @nendo.replStr( " #! \n #t" ).should == "#t"
555
- @nendo.replStr( " #! \n 100" ).should == "100"
556
- @nendo.replStr( " #! 123 \n 100" ).should == "100"
557
- @nendo.replStr( " '#?=1" ).should == "(debug-print 1 \"(string)\" 1 '1)"
558
- @nendo.replStr( " #b0 " ).should == Integer("0b0").to_s
559
- @nendo.replStr( " #b01 " ).should == Integer("0b01").to_s
560
- @nendo.replStr( " #b10 " ).should == Integer("0b10").to_s
561
- @nendo.replStr( " #b00000001 " ).should == Integer("0b00000001").to_s
562
- @nendo.replStr( " #b1010101010101010 " ).should == Integer("0b1010101010101010").to_s
563
- lambda { @nendo.replStr( " #b2 " ) }.should raise_error(RuntimeError)
564
- lambda { @nendo.replStr( " #b02 " ) }.should raise_error(RuntimeError)
565
- lambda { @nendo.replStr( " #bF " ) }.should raise_error(RuntimeError)
566
- @nendo.replStr( " #o0 " ).should == Integer("0o0").to_s
567
- @nendo.replStr( " #o7 " ).should == Integer("0o7").to_s
568
- @nendo.replStr( " #o01 " ).should == Integer("0o01").to_s
569
- @nendo.replStr( " #o10 " ).should == Integer("0o10").to_s
570
- @nendo.replStr( " #o777 " ).should == Integer("0o777").to_s
571
- @nendo.replStr( " #o00000007 " ).should == Integer("0o00000007").to_s
572
- @nendo.replStr( " #o0123456701234567 " ).should == Integer("0o0123456701234567").to_s
573
- lambda { @nendo.replStr( " #o8 " ) }.should raise_error(RuntimeError)
574
- lambda { @nendo.replStr( " #o08 " ) }.should raise_error(RuntimeError)
575
- lambda { @nendo.replStr( " #oA " ) }.should raise_error(RuntimeError)
576
- @nendo.replStr( " #d0 " ).should == Integer("0d0").to_s
577
- @nendo.replStr( " #d9 " ).should == Integer("0d9").to_s
578
- @nendo.replStr( " #d01 " ).should == Integer("0d01").to_s
579
- @nendo.replStr( " #d10 " ).should == Integer("0d10").to_s
580
- @nendo.replStr( " #d999 " ).should == Integer("0d999").to_s
581
- @nendo.replStr( " #d00000009 " ).should == Integer("0d00000009").to_s
582
- @nendo.replStr( " #d0123456701234567 " ).should == Integer("0d0123456701234567").to_s
583
- lambda { @nendo.replStr( " #dA " ) }.should raise_error(RuntimeError)
584
- lambda { @nendo.replStr( " #dF " ) }.should raise_error(RuntimeError)
585
- @nendo.replStr( " #x0 " ).should == Integer("0x0").to_s
586
- @nendo.replStr( " #x9 " ).should == Integer("0x9").to_s
587
- @nendo.replStr( " #xA " ).should == Integer("0xA").to_s
588
- @nendo.replStr( " #xF " ).should == Integer("0xF").to_s
589
- @nendo.replStr( " #x01 " ).should == Integer("0x01").to_s
590
- @nendo.replStr( " #x10 " ).should == Integer("0x10").to_s
591
- @nendo.replStr( " #xFFF " ).should == Integer("0xFFF").to_s
592
- @nendo.replStr( " #x0000000F " ).should == Integer("0x0000000F").to_s
593
- @nendo.replStr( " #x0123456789ABCDEF0123456789ABCDEF " ).should == Integer("0x0123456789ABCDEF0123456789ABCDEF").to_s
594
- lambda { @nendo.replStr( " #xg " ) }.should raise_error(RuntimeError)
595
- lambda { @nendo.replStr( " #xh " ) }.should raise_error(RuntimeError)
596
- lambda { @nendo.replStr( " #xz " ) }.should raise_error(RuntimeError)
597
- lambda { @nendo.replStr( " #xG " ) }.should raise_error(RuntimeError)
598
- lambda { @nendo.replStr( " #xH " ) }.should raise_error(RuntimeError)
599
- lambda { @nendo.replStr( " #xZ " ) }.should raise_error(RuntimeError)
600
- lambda { @nendo.replStr( " #a " ) }.should raise_error(NameError)
601
- lambda { @nendo.replStr( " #c " ) }.should raise_error(NameError)
602
- lambda { @nendo.replStr( " #e " ) }.should raise_error(NameError)
603
- lambda { @nendo.replStr( " #tt " ) }.should raise_error(NameError)
604
- lambda { @nendo.replStr( " #ff " ) }.should raise_error(NameError)
605
- lambda { @nendo.replStr( " #abc " ) }.should raise_error(NameError)
606
- lambda { @nendo.replStr( " #? " ) }.should raise_error(NameError)
607
- lambda { @nendo.replStr( " #?a " ) }.should raise_error(NameError)
608
- lambda { @nendo.replStr( " #= " ) }.should raise_error(NameError)
609
- lambda { @nendo.replStr( " #?? " ) }.should raise_error(NameError)
562
+ @nendo.evalStr( " #t " ).should == "#t"
563
+ @nendo.evalStr( " #f " ).should == "#f"
564
+ @nendo.evalStr( " '#( 1 ) " ).should == "#(1)"
565
+ @nendo.evalStr( " '#() " ).should == "#()"
566
+ @nendo.evalStr( " #! \n #t" ).should == "#t"
567
+ @nendo.evalStr( " #! \n 100" ).should == "100"
568
+ @nendo.evalStr( " #! 123 \n 100" ).should == "100"
569
+ @nendo.evalStr( " '#?=1" ).should == "(debug-print 1 \"(string)\" 1 '1)"
570
+ @nendo.evalStr( " #b0 " ).should == Integer("0b0").to_s
571
+ @nendo.evalStr( " #b01 " ).should == Integer("0b01").to_s
572
+ @nendo.evalStr( " #b10 " ).should == Integer("0b10").to_s
573
+ @nendo.evalStr( " #b00000001 " ).should == Integer("0b00000001").to_s
574
+ @nendo.evalStr( " #b1010101010101010 " ).should == Integer("0b1010101010101010").to_s
575
+ lambda { @nendo.evalStr( " #b2 " ) }.should raise_error(RuntimeError)
576
+ lambda { @nendo.evalStr( " #b02 " ) }.should raise_error(RuntimeError)
577
+ lambda { @nendo.evalStr( " #bF " ) }.should raise_error(RuntimeError)
578
+ @nendo.evalStr( " #o0 " ).should == Integer("0o0").to_s
579
+ @nendo.evalStr( " #o7 " ).should == Integer("0o7").to_s
580
+ @nendo.evalStr( " #o01 " ).should == Integer("0o01").to_s
581
+ @nendo.evalStr( " #o10 " ).should == Integer("0o10").to_s
582
+ @nendo.evalStr( " #o777 " ).should == Integer("0o777").to_s
583
+ @nendo.evalStr( " #o00000007 " ).should == Integer("0o00000007").to_s
584
+ @nendo.evalStr( " #o0123456701234567 " ).should == Integer("0o0123456701234567").to_s
585
+ lambda { @nendo.evalStr( " #o8 " ) }.should raise_error(RuntimeError)
586
+ lambda { @nendo.evalStr( " #o08 " ) }.should raise_error(RuntimeError)
587
+ lambda { @nendo.evalStr( " #oA " ) }.should raise_error(RuntimeError)
588
+ @nendo.evalStr( " #d0 " ).should == Integer("0d0").to_s
589
+ @nendo.evalStr( " #d9 " ).should == Integer("0d9").to_s
590
+ @nendo.evalStr( " #d01 " ).should == Integer("0d01").to_s
591
+ @nendo.evalStr( " #d10 " ).should == Integer("0d10").to_s
592
+ @nendo.evalStr( " #d999 " ).should == Integer("0d999").to_s
593
+ @nendo.evalStr( " #d00000009 " ).should == Integer("0d00000009").to_s
594
+ @nendo.evalStr( " #d0123456701234567 " ).should == Integer("0d0123456701234567").to_s
595
+ lambda { @nendo.evalStr( " #dA " ) }.should raise_error(RuntimeError)
596
+ lambda { @nendo.evalStr( " #dF " ) }.should raise_error(RuntimeError)
597
+ @nendo.evalStr( " #x0 " ).should == Integer("0x0").to_s
598
+ @nendo.evalStr( " #x9 " ).should == Integer("0x9").to_s
599
+ @nendo.evalStr( " #xA " ).should == Integer("0xA").to_s
600
+ @nendo.evalStr( " #xF " ).should == Integer("0xF").to_s
601
+ @nendo.evalStr( " #x01 " ).should == Integer("0x01").to_s
602
+ @nendo.evalStr( " #x10 " ).should == Integer("0x10").to_s
603
+ @nendo.evalStr( " #xFFF " ).should == Integer("0xFFF").to_s
604
+ @nendo.evalStr( " #x0000000F " ).should == Integer("0x0000000F").to_s
605
+ @nendo.evalStr( " #x0123456789ABCDEF0123456789ABCDEF " ).should == Integer("0x0123456789ABCDEF0123456789ABCDEF").to_s
606
+ lambda { @nendo.evalStr( " #xg " ) }.should raise_error(RuntimeError)
607
+ lambda { @nendo.evalStr( " #xh " ) }.should raise_error(RuntimeError)
608
+ lambda { @nendo.evalStr( " #xz " ) }.should raise_error(RuntimeError)
609
+ lambda { @nendo.evalStr( " #xG " ) }.should raise_error(RuntimeError)
610
+ lambda { @nendo.evalStr( " #xH " ) }.should raise_error(RuntimeError)
611
+ lambda { @nendo.evalStr( " #xZ " ) }.should raise_error(RuntimeError)
612
+ lambda { @nendo.evalStr( " #a " ) }.should raise_error(NameError)
613
+ lambda { @nendo.evalStr( " #c " ) }.should raise_error(NameError)
614
+ lambda { @nendo.evalStr( " #e " ) }.should raise_error(NameError)
615
+ lambda { @nendo.evalStr( " #tt " ) }.should raise_error(NameError)
616
+ lambda { @nendo.evalStr( " #ff " ) }.should raise_error(NameError)
617
+ lambda { @nendo.evalStr( " #abc " ) }.should raise_error(NameError)
618
+ lambda { @nendo.evalStr( " #? " ) }.should raise_error(NameError)
619
+ lambda { @nendo.evalStr( " #?a " ) }.should raise_error(NameError)
620
+ lambda { @nendo.evalStr( " #= " ) }.should raise_error(NameError)
621
+ lambda { @nendo.evalStr( " #?? " ) }.should raise_error(NameError)
622
+ end
623
+ end
624
+
625
+ describe Nendo, "when use regexp litteral and library functions " do
626
+ before do
627
+ @nendo = Nendo::Core.new()
628
+ @nendo.loadInitFile
629
+ end
630
+ it "should" do
631
+ @nendo.evalStr( " #/abc/ " ).should == "#/abc/"
632
+ @nendo.evalStr( " #/[a-z]/ " ).should == "#/[a-z]/"
633
+ @nendo.evalStr( " #/[a-zA-Z0-9]+/ " ).should == "#/[a-zA-Z0-9]+/"
634
+ @nendo.evalStr( " #/\\d/ " ).should == "#/\\d/"
635
+ @nendo.evalStr( " #/[\\/]/ " ).should == "#/[/]/"
636
+ @nendo.evalStr( " #/abc/i " ).should == "#/abc/i"
637
+ @nendo.evalStr( " #/[a-z]/i " ).should == "#/[a-z]/i"
638
+ lambda { @nendo.evalStr( " #/[a-z]/I " ) }.should raise_error(NameError)
639
+ lambda { @nendo.evalStr( " #/[a-z]/a " ) }.should raise_error(NameError)
640
+
641
+ @nendo.evalStr( " (string->regexp \"abc\") " ).should == "#/abc/"
642
+ @nendo.evalStr( " (string->regexp \"[a-z]\") " ).should == "#/[a-z]/"
643
+ @nendo.evalStr( " (string->regexp \"[a-zA-Z0-9]+\" ) " ).should == "#/[a-zA-Z0-9]+/"
644
+ @nendo.evalStr( " (string->regexp \"\\\\d\" ) " ).should == "#/\\d/"
645
+ @nendo.evalStr( " (regexp? #/str/ ) " ).should == "#t"
646
+ @nendo.evalStr( " (regexp? #/str/i ) " ).should == "#t"
647
+ @nendo.evalStr( " (regexp? \"str\" ) " ).should == "#f"
648
+ @nendo.evalStr( " (regexp? 'str) " ).should == "#f"
649
+ @nendo.evalStr( " (regexp? (. \"str\" intern)) " ).should == "#f"
650
+ @nendo.evalStr( " (regexp? 100) " ).should == "#f"
651
+
652
+ @nendo.evalStr( " (regexp->string #/abc/ ) " ).should == '"abc"'
653
+ @nendo.evalStr( " (regexp->string #/[a-z]/ ) " ).should == '"[a-z]"'
654
+ @nendo.evalStr( " (regexp->string #/[a-zA-Z0-9]+/ ) " ).should == '"[a-zA-Z0-9]+"'
655
+ @nendo.evalStr( ' (regexp->string #/\d+/ ) ' ).should == '"\\\\d+"'
656
+
657
+ @nendo.evalStr( ' (define matchdata (rxmatch #/(\d+):(\d+)/ "foo314:2000bar")) ' ).should == '314:2000'
658
+ @nendo.evalStr( ' (rxmatch-start matchdata) ' ).should == '3'
659
+ @nendo.evalStr( ' (rxmatch-start matchdata 0) ' ).should == '3'
660
+ @nendo.evalStr( ' (rxmatch-start matchdata 1) ' ).should == '3'
661
+ @nendo.evalStr( ' (rxmatch-start matchdata 2) ' ).should == '7'
662
+ @nendo.evalStr( ' (rxmatch-end matchdata) ' ).should == '11'
663
+ @nendo.evalStr( ' (rxmatch-end matchdata 0) ' ).should == '11'
664
+ @nendo.evalStr( ' (rxmatch-end matchdata 1) ' ).should == '6'
665
+ @nendo.evalStr( ' (rxmatch-end matchdata 2) ' ).should == '11'
666
+ @nendo.evalStr( ' (rxmatch-substring matchdata) ' ).should == '"314:2000"'
667
+ @nendo.evalStr( ' (rxmatch-substring matchdata 0) ' ).should == '"314:2000"'
668
+ @nendo.evalStr( ' (rxmatch-substring matchdata 1) ' ).should == '"314"'
669
+ @nendo.evalStr( ' (rxmatch-substring matchdata 2) ' ).should == '"2000"'
670
+ @nendo.evalStr( ' (rxmatch-num-matches matchdata) ' ).should == '3'
671
+
672
+ @nendo.evalStr( ' (define matchdata (rxmatch #/(\w+)@([\w.]+)/ "foo@example.com")) ' ).should == 'foo@example.com'
673
+ @nendo.evalStr( ' (rxmatch-substring matchdata) ' ).should == '"foo@example.com"'
674
+ @nendo.evalStr( ' (rxmatch-substring matchdata 0) ' ).should == '"foo@example.com"'
675
+ @nendo.evalStr( ' (rxmatch-substring matchdata 1) ' ).should == '"foo"'
676
+ @nendo.evalStr( ' (rxmatch-substring matchdata 2) ' ).should == '"example.com"'
677
+
678
+ @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com")' ).should == '"foo@example.com"'
679
+ @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com" 0)' ).should == '"foo@example.com"'
680
+ @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com" 1)' ).should == '"foo"'
681
+ @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com" 2)' ).should == '"example.com"'
682
+
683
+ @nendo.evalStr( ' (rxmatch->string #/abc/ "000abc00ABC000")' ).should == '"abc"'
684
+ @nendo.evalStr( ' (rxmatch->string #/ABC/ "000abc00ABC000")' ).should == '"ABC"'
685
+ @nendo.evalStr( ' (rxmatch->string #/abc/i "abc")' ).should == '"abc"'
686
+ @nendo.evalStr( ' (rxmatch->string #/abc/i "ABC")' ).should == '"ABC"'
687
+ @nendo.evalStr( ' (rxmatch->string #/ABC/i "abc")' ).should == '"abc"'
688
+ @nendo.evalStr( ' (rxmatch->string #/abc/i "AbC")' ).should == '"AbC"'
689
+
690
+ @nendo.evalStr( ' (rxmatch #/abc/i "xxx")' ).should == '#f'
691
+ @nendo.evalStr( ' (rxmatch #/XXX/ "xxx")' ).should == '#f'
692
+ @nendo.evalStr( ' (rxmatch->string #/abc/i "xxx")' ).should == '#f'
693
+ @nendo.evalStr( ' (rxmatch->string #/XXX/ "xxx")' ).should == '#f'
694
+
695
+ pending( "JRuby can't compute correctly" ) if defined? JRUBY_VERSION
696
+ @nendo.evalStr( ' (define matchdata (rxmatch #/([あ-ん])([あ-ん])([あ-ん])([あ-ん])([あ-ん])/ "ABC漢字あいうえお漢字ABC")) ' ).should == 'あいうえお'
697
+ @nendo.evalStr( ' (rxmatch-start matchdata) ' ).should == '5'
698
+ @nendo.evalStr( ' (rxmatch-end matchdata) ' ).should == '10'
699
+ @nendo.evalStr( ' (rxmatch-substring matchdata) ' ).should == '"あいうえお"'
700
+ @nendo.evalStr( ' (rxmatch-substring matchdata 1) ' ).should == '"あ"'
701
+ @nendo.evalStr( ' (rxmatch-substring matchdata 2) ' ).should == '"い"'
702
+ @nendo.evalStr( ' (rxmatch-substring matchdata 3) ' ).should == '"う"'
703
+ end
704
+ end
705
+
706
+
707
+ class TestClassForBlockArgument
708
+ def arg1
709
+ yield 100
710
+ end
711
+ def arg2
712
+ yield 100,200
713
+ end
714
+ def arg5
715
+ yield 10,20,30,40,50
716
+ end
717
+ end
718
+
719
+ describe Nendo, "when use &block(Ruby's block) " do
720
+ before do
721
+ @nendo = Nendo::Core.new()
722
+ end
723
+
724
+ it "should" do
725
+ @nendo.evalStr( " (define testclass (TestClassForBlockArgument.new)) testclass.class" ).should == "TestClassForBlockArgument"
726
+ @nendo.evalStr( " (testclass.arg1 (&block (a) (list a))) " ).should == "(100)"
727
+ @nendo.evalStr( " (testclass.arg2 (&block (a b) (cons a b))) " ).should == "(100 . 200)"
728
+ @nendo.evalStr( " (testclass.arg5 (&block (a b c d e) (list a b c d e))) " ).should == "(10 20 30 40 50)"
729
+ @nendo.evalStr( " (testclass.arg5 (&block (a b c d e) (to-arr (list a b c d e)))) " ).should == "#(10 20 30 40 50)"
610
730
  end
611
731
  end
612
732
 
@@ -615,272 +735,272 @@ describe Nendo, "when read various vector expressions" do
615
735
  @nendo = Nendo::Core.new()
616
736
  end
617
737
  it "should" do
618
- @nendo.replStr( " '() " ).should == "()"
619
- @nendo.replStr( " '[] " ).should == "()"
620
- @nendo.replStr( " '#( 1 ) " ).should == "#(1)"
621
- lambda { @nendo.replStr( " '#(( 1 ) " ) }.should raise_error( RuntimeError )
622
- @nendo.replStr( " '#( 1 2 ) " ).should == "#(1 2)"
623
- @nendo.replStr( " '#( 1 () ) " ).should == "#(1 ())"
624
- @nendo.replStr( " '#( () 2 ) " ).should == "#(() 2)"
625
- lambda { @nendo.replStr( " '#( 1 . 2 ) " ) }.should raise_error( RuntimeError )
626
- lambda { @nendo.replStr( " #(+ 1 2) " ) }.should raise_error( RuntimeError )
627
- @nendo.replStr( " '#( 1 #( 11 )) " ).should == "#(1 #(11))"
628
- @nendo.replStr( " '#( 1 #( 11 12 )) " ).should == "#(1 #(11 12))"
629
- @nendo.replStr( " '#( 1 #( 11 #( 111 ))) " ).should == "#(1 #(11 #(111)))"
630
- @nendo.replStr( " '#( 1 #( 11 #( 111 112))) " ).should == "#(1 #(11 #(111 112)))"
631
- @nendo.replStr( " '#(1 2 3) " ).should == "#(1 2 3)"
632
- @nendo.replStr( " '#(1.1 2.2 3.3) " ).should == "#(1.1 2.2 3.3)"
633
- @nendo.replStr( " '#(a bb ccc dddd) " ).should == "#(a bb ccc dddd)"
634
- @nendo.replStr( " '#(a (b) ((c)) (((d)))) " ).should == "#(a (b) ((c)) (((d))))"
738
+ @nendo.evalStr( " '() " ).should == "()"
739
+ @nendo.evalStr( " '[] " ).should == "()"
740
+ @nendo.evalStr( " '#( 1 ) " ).should == "#(1)"
741
+ lambda { @nendo.evalStr( " '#(( 1 ) " ) }.should raise_error( RuntimeError )
742
+ @nendo.evalStr( " '#( 1 2 ) " ).should == "#(1 2)"
743
+ @nendo.evalStr( " '#( 1 () ) " ).should == "#(1 ())"
744
+ @nendo.evalStr( " '#( () 2 ) " ).should == "#(() 2)"
745
+ lambda { @nendo.evalStr( " '#( 1 . 2 ) " ) }.should raise_error( RuntimeError )
746
+ lambda { @nendo.evalStr( " #(+ 1 2) " ) }.should raise_error( RuntimeError )
747
+ @nendo.evalStr( " '#( 1 #( 11 )) " ).should == "#(1 #(11))"
748
+ @nendo.evalStr( " '#( 1 #( 11 12 )) " ).should == "#(1 #(11 12))"
749
+ @nendo.evalStr( " '#( 1 #( 11 #( 111 ))) " ).should == "#(1 #(11 #(111)))"
750
+ @nendo.evalStr( " '#( 1 #( 11 #( 111 112))) " ).should == "#(1 #(11 #(111 112)))"
751
+ @nendo.evalStr( " '#(1 2 3) " ).should == "#(1 2 3)"
752
+ @nendo.evalStr( " '#(1.1 2.2 3.3) " ).should == "#(1.1 2.2 3.3)"
753
+ @nendo.evalStr( " '#(a bb ccc dddd) " ).should == "#(a bb ccc dddd)"
754
+ @nendo.evalStr( " '#(a (b) ((c)) (((d)))) " ).should == "#(a (b) ((c)) (((d))))"
635
755
  end
636
756
  end
637
757
 
638
- describe Nendo, "when call replStr() with built-in functions" do
758
+ describe Nendo, "when call evalStr() with built-in functions" do
639
759
  before do
640
760
  @nendo = Nendo::Core.new()
641
761
  end
642
762
  it "should" do
643
- @nendo.replStr( " (car '(1 2 3 4)) " ).should == "1"
644
- @nendo.replStr( " (cdr '(1 2 3 4)) " ).should == "(2 3 4)"
645
- @nendo.replStr( " (null? '()) " ).should == "#t"
646
- @nendo.replStr( " (null? '(1)) " ).should == "#f"
647
- @nendo.replStr( " (null? false) " ).should == "#f"
648
- @nendo.replStr( " (null? nil) " ).should == "#f"
649
- @nendo.replStr( " (null? true) " ).should == "#f"
650
- @nendo.replStr( " (cons 1 2) " ).should == "(1 . 2)"
651
- @nendo.replStr( " (cons 1 '(2 3)) " ).should == "(1 2 3)"
652
- @nendo.replStr( " (cons '(1 2) '(3 4)) " ).should == "((1 2) 3 4)"
653
- @nendo.replStr( " (cons '(1 2) '((3 4))) " ).should == "((1 2) (3 4))"
654
- @nendo.replStr( " (cons '() '()) " ).should == "(())"
655
- @nendo.replStr( " (cons '() (cdr '(100))) " ).should == "(())"
656
- @nendo.replStr( " (cons '() (car '(()))) " ).should == "(())"
657
- @nendo.replStr( " (cons (car '(())) '()) " ).should == "(())"
658
- @nendo.replStr( " (cons (car '(())) (car '(()))) " ).should == "(())"
659
- @nendo.replStr( " (cons '() (cdr '(100))) " ).should == "(())"
660
- @nendo.replStr( " (cons (cdr '(100)) '()) " ).should == "(())"
661
- @nendo.replStr( " (cons (cdr '(100)) (cdr '(100))) " ).should == "(())"
662
- lambda { @nendo.replStr( " (cons 1 2 3) " ) }.should raise_error(ArgumentError)
663
- lambda { @nendo.replStr( " (cons 1) " ) }.should raise_error(ArgumentError)
664
- lambda { @nendo.replStr( " (cons) " ) }.should raise_error(ArgumentError)
665
- @nendo.replStr( " (list 1 2 3) " ).should == "(1 2 3)"
666
- @nendo.replStr( " (list '(1) '(2) '(3)) " ).should == "((1) (2) (3))"
667
- @nendo.replStr( " (list 'a 'b 'c) " ).should == "(a b c)"
668
- @nendo.replStr( " (list '(a) '((b c))) " ).should == "((a) ((b c)))"
669
- @nendo.replStr( " (list) " ).should == "()"
670
- @nendo.replStr( " (list 1) " ).should == "(1)"
671
- @nendo.replStr( " (define !a 10) !a" ).should == "10"
672
- @nendo.replStr( " (define $a 11) $a" ).should == "11"
673
- @nendo.replStr( " (define %a 12) %a" ).should == "12"
674
- @nendo.replStr( " (define &a 13) &a" ).should == "13"
675
- @nendo.replStr( " (define *a 14) *a" ).should == "14"
676
- @nendo.replStr( " (define +a 15) +a" ).should == "15"
677
- @nendo.replStr( " (define -a 16) -a" ).should == "16"
678
- @nendo.replStr( " (define /a 17) /a" ).should == "17"
679
- @nendo.replStr( " (define <a 18) <a" ).should == "18"
680
- @nendo.replStr( " (define =a 19) =a" ).should == "19"
681
- @nendo.replStr( " (define ?a 20) ?a" ).should == "20"
682
- @nendo.replStr( " (define @a 21) @a" ).should == "21"
683
- @nendo.replStr( " (define ^a 22) ^a" ).should == "22"
684
- @nendo.replStr( " (define ~a 23) ~a" ).should == "23"
685
- @nendo.replStr( " (define a! 30) a!" ).should == "30"
686
- @nendo.replStr( " (define a$ 31) a$" ).should == "31"
687
- @nendo.replStr( " (define a% 32) a%" ).should == "32"
688
- @nendo.replStr( " (define a& 33) a&" ).should == "33"
689
- @nendo.replStr( " (define a* 34) a*" ).should == "34"
690
- @nendo.replStr( " (define a+ 35) a+" ).should == "35"
691
- @nendo.replStr( " (define a- 36) a-" ).should == "36"
692
- @nendo.replStr( " (define a/ 37) a/" ).should == "37"
693
- @nendo.replStr( " (define a< 38) a<" ).should == "38"
694
- @nendo.replStr( " (define a= 39) a=" ).should == "39"
695
- @nendo.replStr( " (define a? 40) a?" ).should == "40"
696
- @nendo.replStr( " (define a@ 41) a@" ).should == "41"
697
- @nendo.replStr( " (define a^ 42) a^" ).should == "42"
698
- @nendo.replStr( " (define a~ 43) a~" ).should == "43"
699
- @nendo.replStr( " (define aFunc (lambda (x) x)) true" ).should == "#t"
700
- @nendo.replStr( " (define aMacro (macro (x) x)) true" ).should == "#t"
701
- @nendo.replStr( " (define a! 123) a!" ).should == "123"
702
- @nendo.replStr( " (define b? 321) b?" ).should == "321"
703
- @nendo.replStr( " (define a-b 1234) a-b" ).should == "1234"
704
- @nendo.replStr( " (define start-end!? 4321) start-end!?" ).should == "4321"
705
- @nendo.replStr( " (procedure? car) " ).should == "#t"
706
- @nendo.replStr( " (procedure? aFunc) " ).should == "#t"
707
- @nendo.replStr( " (procedure? aMacro) " ).should == "#f"
708
- @nendo.replStr( " (procedure? 1) " ).should == "#f"
709
- @nendo.replStr( " (procedure? 1.1) " ).should == "#f"
710
- @nendo.replStr( " (procedure? \"str\") " ).should == "#f"
711
- @nendo.replStr( " (procedure? 'a) " ).should == "#f"
712
- @nendo.replStr( " (procedure? '(1)) " ).should == "#f"
713
- @nendo.replStr( " (procedure? '()) " ).should == "#f"
714
- @nendo.replStr( " (symbol? car) " ).should == "#f"
715
- @nendo.replStr( " (symbol? aFunc) " ).should == "#f"
716
- @nendo.replStr( " (symbol? aMacro) " ).should == "#f"
717
- @nendo.replStr( " (symbol? 1) " ).should == "#f"
718
- @nendo.replStr( " (symbol? 1.1) " ).should == "#f"
719
- @nendo.replStr( " (symbol? \"str\") " ).should == "#f"
720
- @nendo.replStr( " (symbol? 'a) " ).should == "#t"
721
- @nendo.replStr( " (symbol? '(1)) " ).should == "#f"
722
- @nendo.replStr( " (symbol? '()) " ).should == "#f"
723
- @nendo.replStr( " (pair? car) " ).should == "#f"
724
- @nendo.replStr( " (pair? aFunc) " ).should == "#f"
725
- @nendo.replStr( " (pair? aMacro) " ).should == "#f"
726
- @nendo.replStr( " (pair? 1) " ).should == "#f"
727
- @nendo.replStr( " (pair? 1.1) " ).should == "#f"
728
- @nendo.replStr( " (pair? \"str\") " ).should == "#f"
729
- @nendo.replStr( " (pair? 'a) " ).should == "#f"
730
- @nendo.replStr( " (pair? '(1)) " ).should == "#t"
731
- @nendo.replStr( " (pair? '()) " ).should == "#f"
732
- @nendo.replStr( " (number? car) " ).should == "#f"
733
- @nendo.replStr( " (number? aFunc) " ).should == "#f"
734
- @nendo.replStr( " (number? aMacro) " ).should == "#f"
735
- @nendo.replStr( " (number? 1) " ).should == "#t"
736
- @nendo.replStr( " (number? 1.1) " ).should == "#t"
737
- @nendo.replStr( " (number? \"str\") " ).should == "#f"
738
- @nendo.replStr( " (number? 'a) " ).should == "#f"
739
- @nendo.replStr( " (number? '(1)) " ).should == "#f"
740
- @nendo.replStr( " (number? '()) " ).should == "#f"
741
- @nendo.replStr( " (integer? car) " ).should == "#f"
742
- @nendo.replStr( " (integer? aFunc) " ).should == "#f"
743
- @nendo.replStr( " (integer? aMacro) " ).should == "#f"
744
- @nendo.replStr( " (integer? 1) " ).should == "#t"
745
- @nendo.replStr( " (integer? 1.1) " ).should == "#f"
746
- @nendo.replStr( " (integer? \"str\") " ).should == "#f"
747
- @nendo.replStr( " (integer? 'a) " ).should == "#f"
748
- @nendo.replStr( " (integer? '(1)) " ).should == "#f"
749
- @nendo.replStr( " (integer? '()) " ).should == "#f"
750
- @nendo.replStr( " (string? car) " ).should == "#f"
751
- @nendo.replStr( " (string? aFunc) " ).should == "#f"
752
- @nendo.replStr( " (string? aMacro) " ).should == "#f"
753
- @nendo.replStr( " (string? 1) " ).should == "#f"
754
- @nendo.replStr( " (string? 1.1) " ).should == "#f"
755
- @nendo.replStr( " (string? \"str\") " ).should == "#t"
756
- @nendo.replStr( " (string? 'a) " ).should == "#f"
757
- @nendo.replStr( " (string? '(1)) " ).should == "#f"
758
- @nendo.replStr( " (string? '()) " ).should == "#f"
759
- @nendo.replStr( " (macro? car) " ).should == "#f"
760
- @nendo.replStr( " (macro? aFunc) " ).should == "#f"
761
- @nendo.replStr( " (macro? aMacro) " ).should == "#t"
762
- @nendo.replStr( " (macro? 1) " ).should == "#f"
763
- @nendo.replStr( " (macro? 1.1) " ).should == "#f"
764
- @nendo.replStr( " (macro? \"str\") " ).should == "#f"
765
- @nendo.replStr( " (macro? 'a) " ).should == "#f"
766
- @nendo.replStr( " (macro? '(1)) " ).should == "#f"
767
- @nendo.replStr( " (macro? '()) " ).should == "#f"
768
- @nendo.replStr( " (length '()) " ).should == "0"
769
- @nendo.replStr( " (length '(1)) " ).should == "1"
770
- @nendo.replStr( " (length '((1))) " ).should == "1"
771
- @nendo.replStr( " (length '(1 2)) " ).should == "2"
772
- lambda { @nendo.replStr( " (length \"str\") " ) }.should raise_error(TypeError)
773
- lambda { @nendo.replStr( " (length 1) " ) }.should raise_error(TypeError)
774
- @nendo.replStr( " (symbol->string 'sym) " ).should == '"sym"'
775
- @nendo.replStr( " (string->symbol \"sym\") " ).should == 'sym'
776
- @nendo.replStr( ' (string-join \'("Aa" "Bb" "Cc") ) ' ).should == '"AaBbCc"'
777
- @nendo.replStr( ' (string-join \'("Aa" "Bb" "Cc") ":") ' ).should == '"Aa:Bb:Cc"'
778
- @nendo.replStr( ' (string-join \'("Aa" "Bb" "Cc") "//") ' ).should == '"Aa//Bb//Cc"'
779
- lambda { @nendo.replStr( ' (string-join \'("Aa" "Bb" "Cc") 100) ' ) }.should raise_error(TypeError)
780
- lambda { @nendo.replStr( ' (string-join \'("Aa" "Bb" "Cc") :xx) ' ) }.should raise_error(TypeError)
763
+ @nendo.evalStr( " (car '(1 2 3 4)) " ).should == "1"
764
+ @nendo.evalStr( " (cdr '(1 2 3 4)) " ).should == "(2 3 4)"
765
+ @nendo.evalStr( " (null? '()) " ).should == "#t"
766
+ @nendo.evalStr( " (null? '(1)) " ).should == "#f"
767
+ @nendo.evalStr( " (null? false) " ).should == "#f"
768
+ @nendo.evalStr( " (null? nil) " ).should == "#f"
769
+ @nendo.evalStr( " (null? true) " ).should == "#f"
770
+ @nendo.evalStr( " (cons 1 2) " ).should == "(1 . 2)"
771
+ @nendo.evalStr( " (cons 1 '(2 3)) " ).should == "(1 2 3)"
772
+ @nendo.evalStr( " (cons '(1 2) '(3 4)) " ).should == "((1 2) 3 4)"
773
+ @nendo.evalStr( " (cons '(1 2) '((3 4))) " ).should == "((1 2) (3 4))"
774
+ @nendo.evalStr( " (cons '() '()) " ).should == "(())"
775
+ @nendo.evalStr( " (cons '() (cdr '(100))) " ).should == "(())"
776
+ @nendo.evalStr( " (cons '() (car '(()))) " ).should == "(())"
777
+ @nendo.evalStr( " (cons (car '(())) '()) " ).should == "(())"
778
+ @nendo.evalStr( " (cons (car '(())) (car '(()))) " ).should == "(())"
779
+ @nendo.evalStr( " (cons '() (cdr '(100))) " ).should == "(())"
780
+ @nendo.evalStr( " (cons (cdr '(100)) '()) " ).should == "(())"
781
+ @nendo.evalStr( " (cons (cdr '(100)) (cdr '(100))) " ).should == "(())"
782
+ lambda { @nendo.evalStr( " (cons 1 2 3) " ) }.should raise_error(ArgumentError)
783
+ lambda { @nendo.evalStr( " (cons 1) " ) }.should raise_error(ArgumentError)
784
+ lambda { @nendo.evalStr( " (cons) " ) }.should raise_error(ArgumentError)
785
+ @nendo.evalStr( " (list 1 2 3) " ).should == "(1 2 3)"
786
+ @nendo.evalStr( " (list '(1) '(2) '(3)) " ).should == "((1) (2) (3))"
787
+ @nendo.evalStr( " (list 'a 'b 'c) " ).should == "(a b c)"
788
+ @nendo.evalStr( " (list '(a) '((b c))) " ).should == "((a) ((b c)))"
789
+ @nendo.evalStr( " (list) " ).should == "()"
790
+ @nendo.evalStr( " (list 1) " ).should == "(1)"
791
+ @nendo.evalStr( " (define !a 10) !a" ).should == "10"
792
+ @nendo.evalStr( " (define $a 11) $a" ).should == "11"
793
+ @nendo.evalStr( " (define %a 12) %a" ).should == "12"
794
+ @nendo.evalStr( " (define &a 13) &a" ).should == "13"
795
+ @nendo.evalStr( " (define *a 14) *a" ).should == "14"
796
+ @nendo.evalStr( " (define +a 15) +a" ).should == "15"
797
+ @nendo.evalStr( " (define -a 16) -a" ).should == "16"
798
+ @nendo.evalStr( " (define /a 17) /a" ).should == "17"
799
+ @nendo.evalStr( " (define <a 18) <a" ).should == "18"
800
+ @nendo.evalStr( " (define =a 19) =a" ).should == "19"
801
+ @nendo.evalStr( " (define ?a 20) ?a" ).should == "20"
802
+ @nendo.evalStr( " (define @a 21) @a" ).should == "21"
803
+ @nendo.evalStr( " (define ^a 22) ^a" ).should == "22"
804
+ @nendo.evalStr( " (define ~a 23) ~a" ).should == "23"
805
+ @nendo.evalStr( " (define a! 30) a!" ).should == "30"
806
+ @nendo.evalStr( " (define a$ 31) a$" ).should == "31"
807
+ @nendo.evalStr( " (define a% 32) a%" ).should == "32"
808
+ @nendo.evalStr( " (define a& 33) a&" ).should == "33"
809
+ @nendo.evalStr( " (define a* 34) a*" ).should == "34"
810
+ @nendo.evalStr( " (define a+ 35) a+" ).should == "35"
811
+ @nendo.evalStr( " (define a- 36) a-" ).should == "36"
812
+ @nendo.evalStr( " (define a/ 37) a/" ).should == "37"
813
+ @nendo.evalStr( " (define a< 38) a<" ).should == "38"
814
+ @nendo.evalStr( " (define a= 39) a=" ).should == "39"
815
+ @nendo.evalStr( " (define a? 40) a?" ).should == "40"
816
+ @nendo.evalStr( " (define a@ 41) a@" ).should == "41"
817
+ @nendo.evalStr( " (define a^ 42) a^" ).should == "42"
818
+ @nendo.evalStr( " (define a~ 43) a~" ).should == "43"
819
+ @nendo.evalStr( " (define aFunc (lambda (x) x)) true" ).should == "#t"
820
+ @nendo.evalStr( " (define aMacro (macro (x) x)) true" ).should == "#t"
821
+ @nendo.evalStr( " (define a! 123) a!" ).should == "123"
822
+ @nendo.evalStr( " (define b? 321) b?" ).should == "321"
823
+ @nendo.evalStr( " (define a-b 1234) a-b" ).should == "1234"
824
+ @nendo.evalStr( " (define start-end!? 4321) start-end!?" ).should == "4321"
825
+ @nendo.evalStr( " (procedure? car) " ).should == "#t"
826
+ @nendo.evalStr( " (procedure? aFunc) " ).should == "#t"
827
+ @nendo.evalStr( " (procedure? aMacro) " ).should == "#f"
828
+ @nendo.evalStr( " (procedure? 1) " ).should == "#f"
829
+ @nendo.evalStr( " (procedure? 1.1) " ).should == "#f"
830
+ @nendo.evalStr( " (procedure? \"str\") " ).should == "#f"
831
+ @nendo.evalStr( " (procedure? 'a) " ).should == "#f"
832
+ @nendo.evalStr( " (procedure? '(1)) " ).should == "#f"
833
+ @nendo.evalStr( " (procedure? '()) " ).should == "#f"
834
+ @nendo.evalStr( " (symbol? car) " ).should == "#f"
835
+ @nendo.evalStr( " (symbol? aFunc) " ).should == "#f"
836
+ @nendo.evalStr( " (symbol? aMacro) " ).should == "#f"
837
+ @nendo.evalStr( " (symbol? 1) " ).should == "#f"
838
+ @nendo.evalStr( " (symbol? 1.1) " ).should == "#f"
839
+ @nendo.evalStr( " (symbol? \"str\") " ).should == "#f"
840
+ @nendo.evalStr( " (symbol? 'a) " ).should == "#t"
841
+ @nendo.evalStr( " (symbol? '(1)) " ).should == "#f"
842
+ @nendo.evalStr( " (symbol? '()) " ).should == "#f"
843
+ @nendo.evalStr( " (pair? car) " ).should == "#f"
844
+ @nendo.evalStr( " (pair? aFunc) " ).should == "#f"
845
+ @nendo.evalStr( " (pair? aMacro) " ).should == "#f"
846
+ @nendo.evalStr( " (pair? 1) " ).should == "#f"
847
+ @nendo.evalStr( " (pair? 1.1) " ).should == "#f"
848
+ @nendo.evalStr( " (pair? \"str\") " ).should == "#f"
849
+ @nendo.evalStr( " (pair? 'a) " ).should == "#f"
850
+ @nendo.evalStr( " (pair? '(1)) " ).should == "#t"
851
+ @nendo.evalStr( " (pair? '()) " ).should == "#f"
852
+ @nendo.evalStr( " (number? car) " ).should == "#f"
853
+ @nendo.evalStr( " (number? aFunc) " ).should == "#f"
854
+ @nendo.evalStr( " (number? aMacro) " ).should == "#f"
855
+ @nendo.evalStr( " (number? 1) " ).should == "#t"
856
+ @nendo.evalStr( " (number? 1.1) " ).should == "#t"
857
+ @nendo.evalStr( " (number? \"str\") " ).should == "#f"
858
+ @nendo.evalStr( " (number? 'a) " ).should == "#f"
859
+ @nendo.evalStr( " (number? '(1)) " ).should == "#f"
860
+ @nendo.evalStr( " (number? '()) " ).should == "#f"
861
+ @nendo.evalStr( " (integer? car) " ).should == "#f"
862
+ @nendo.evalStr( " (integer? aFunc) " ).should == "#f"
863
+ @nendo.evalStr( " (integer? aMacro) " ).should == "#f"
864
+ @nendo.evalStr( " (integer? 1) " ).should == "#t"
865
+ @nendo.evalStr( " (integer? 1.1) " ).should == "#f"
866
+ @nendo.evalStr( " (integer? \"str\") " ).should == "#f"
867
+ @nendo.evalStr( " (integer? 'a) " ).should == "#f"
868
+ @nendo.evalStr( " (integer? '(1)) " ).should == "#f"
869
+ @nendo.evalStr( " (integer? '()) " ).should == "#f"
870
+ @nendo.evalStr( " (string? car) " ).should == "#f"
871
+ @nendo.evalStr( " (string? aFunc) " ).should == "#f"
872
+ @nendo.evalStr( " (string? aMacro) " ).should == "#f"
873
+ @nendo.evalStr( " (string? 1) " ).should == "#f"
874
+ @nendo.evalStr( " (string? 1.1) " ).should == "#f"
875
+ @nendo.evalStr( " (string? \"str\") " ).should == "#t"
876
+ @nendo.evalStr( " (string? 'a) " ).should == "#f"
877
+ @nendo.evalStr( " (string? '(1)) " ).should == "#f"
878
+ @nendo.evalStr( " (string? '()) " ).should == "#f"
879
+ @nendo.evalStr( " (macro? car) " ).should == "#f"
880
+ @nendo.evalStr( " (macro? aFunc) " ).should == "#f"
881
+ @nendo.evalStr( " (macro? aMacro) " ).should == "#t"
882
+ @nendo.evalStr( " (macro? 1) " ).should == "#f"
883
+ @nendo.evalStr( " (macro? 1.1) " ).should == "#f"
884
+ @nendo.evalStr( " (macro? \"str\") " ).should == "#f"
885
+ @nendo.evalStr( " (macro? 'a) " ).should == "#f"
886
+ @nendo.evalStr( " (macro? '(1)) " ).should == "#f"
887
+ @nendo.evalStr( " (macro? '()) " ).should == "#f"
888
+ @nendo.evalStr( " (length '()) " ).should == "0"
889
+ @nendo.evalStr( " (length '(1)) " ).should == "1"
890
+ @nendo.evalStr( " (length '((1))) " ).should == "1"
891
+ @nendo.evalStr( " (length '(1 2)) " ).should == "2"
892
+ lambda { @nendo.evalStr( " (length \"str\") " ) }.should raise_error(TypeError)
893
+ lambda { @nendo.evalStr( " (length 1) " ) }.should raise_error(TypeError)
894
+ @nendo.evalStr( " (symbol->string 'sym) " ).should == '"sym"'
895
+ @nendo.evalStr( " (string->symbol \"sym\") " ).should == 'sym'
896
+ @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") ) ' ).should == '"AaBbCc"'
897
+ @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") ":") ' ).should == '"Aa:Bb:Cc"'
898
+ @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") "//") ' ).should == '"Aa//Bb//Cc"'
899
+ lambda { @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") 100) ' ) }.should raise_error(TypeError)
900
+ lambda { @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") :xx) ' ) }.should raise_error(TypeError)
781
901
  end
782
902
  end
783
903
 
784
- describe Nendo, "when call replStr() with variable modifications" do
904
+ describe Nendo, "when call evalStr() with variable modifications" do
785
905
  before do
786
906
  @nendo = Nendo::Core.new()
787
907
  end
788
908
  it "should" do
789
- @nendo.replStr( " (define x 1) x " ).should == "1"
790
- @nendo.replStr( " (define x 2) x " ).should == "2"
791
- @nendo.replStr( " (define x 100) x " ).should == "100"
792
- @nendo.replStr( " (define x true) x " ).should == "#t"
793
- @nendo.replStr( " (define x false) x " ).should == "#f"
794
- @nendo.replStr( " (define x nil) x " ).should == "nil"
795
- @nendo.replStr( " (define x '()) x " ).should == "()"
796
- @nendo.replStr( " (define x '(1)) x " ).should == "(1)"
797
- @nendo.replStr( " (define x (+ 1 2 3)) x " ).should == "6"
798
- @nendo.replStr( " (define x (sprintf \"$%02X\" 17)) x x x " ).should == '"$11"'
799
- @nendo.replStr( " 1 2 3 " ).should == "3"
800
- @nendo.replStr( " (define x 3.14) (set! x (* x 2)) x " ).should == "6.28"
801
- @nendo.replStr( " 1 \n 2 \n 3 \n " ).should == "3"
802
- @nendo.replStr( " (define a '(1 . 2)) (set-car! a 100) a " ).should == "(100 . 2)"
803
- @nendo.replStr( " (define a '(1 . 2)) (set-car! a '()) a " ).should == "(() . 2)"
804
- @nendo.replStr( " (define a '(1 . 2)) (set-car! a #t) a " ).should == "(#t . 2)"
805
- @nendo.replStr( " (define a '(1 . 2)) (set-car! a #f) a " ).should == "(#f . 2)"
806
- @nendo.replStr( " (define a '(1 . 2)) (set-car! a nil) a " ).should == "(nil . 2)"
807
- @nendo.replStr( " (define a '(1 . 2)) (set-cdr! a 200) a " ).should == "(1 . 200)"
808
- @nendo.replStr( " (define a '(1 . 2)) (set-cdr! a '(2)) a " ).should == "(1 2)"
809
- @nendo.replStr( " (define a '(1 . 2)) (set-cdr! a '()) a " ).should == "(1)"
810
- @nendo.replStr( " (define a '(1 . 2)) (set-cdr! a #t) a " ).should == "(1 . #t)"
811
- @nendo.replStr( " (define a '(1 . 2)) (set-cdr! a #f) a " ).should == "(1 . #f)"
812
- @nendo.replStr( " (define a '(1 . 2)) (set-cdr! a nil) a " ).should == "(1 . nil)"
813
- @nendo.replStr( " (define a '((1 . 2) 3)) (set-car! (car a) 100) a " ).should == "((100 . 2) 3)"
814
- @nendo.replStr( " (define a '((1 . 2) 3)) (set-cdr! (car a) 200) a " ).should == "((1 . 200) 3)"
815
- @nendo.replStr( " (define a '((1 . 2) . 3)) (set-cdr! a 300) a " ).should == "((1 . 2) . 300)"
909
+ @nendo.evalStr( " (define x 1) x " ).should == "1"
910
+ @nendo.evalStr( " (define x 2) x " ).should == "2"
911
+ @nendo.evalStr( " (define x 100) x " ).should == "100"
912
+ @nendo.evalStr( " (define x true) x " ).should == "#t"
913
+ @nendo.evalStr( " (define x false) x " ).should == "#f"
914
+ @nendo.evalStr( " (define x nil) x " ).should == "nil"
915
+ @nendo.evalStr( " (define x '()) x " ).should == "()"
916
+ @nendo.evalStr( " (define x '(1)) x " ).should == "(1)"
917
+ @nendo.evalStr( " (define x (+ 1 2 3)) x " ).should == "6"
918
+ @nendo.evalStr( " (define x (sprintf \"$%02X\" 17)) x x x " ).should == '"$11"'
919
+ @nendo.evalStr( " 1 2 3 " ).should == "3"
920
+ @nendo.evalStr( " (define x 3.14) (set! x (* x 2)) x " ).should == "6.28"
921
+ @nendo.evalStr( " 1 \n 2 \n 3 \n " ).should == "3"
922
+ @nendo.evalStr( " (define a '(1 . 2)) (set-car! a 100) a " ).should == "(100 . 2)"
923
+ @nendo.evalStr( " (define a '(1 . 2)) (set-car! a '()) a " ).should == "(() . 2)"
924
+ @nendo.evalStr( " (define a '(1 . 2)) (set-car! a #t) a " ).should == "(#t . 2)"
925
+ @nendo.evalStr( " (define a '(1 . 2)) (set-car! a #f) a " ).should == "(#f . 2)"
926
+ @nendo.evalStr( " (define a '(1 . 2)) (set-car! a nil) a " ).should == "(nil . 2)"
927
+ @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a 200) a " ).should == "(1 . 200)"
928
+ @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a '(2)) a " ).should == "(1 2)"
929
+ @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a '()) a " ).should == "(1)"
930
+ @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a #t) a " ).should == "(1 . #t)"
931
+ @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a #f) a " ).should == "(1 . #f)"
932
+ @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a nil) a " ).should == "(1 . nil)"
933
+ @nendo.evalStr( " (define a '((1 . 2) 3)) (set-car! (car a) 100) a " ).should == "((100 . 2) 3)"
934
+ @nendo.evalStr( " (define a '((1 . 2) 3)) (set-cdr! (car a) 200) a " ).should == "((1 . 200) 3)"
935
+ @nendo.evalStr( " (define a '((1 . 2) . 3)) (set-cdr! a 300) a " ).should == "((1 . 2) . 300)"
816
936
  end
817
937
  end
818
938
 
819
- describe Nendo, "when call replStr() with undefined variable" do
939
+ describe Nendo, "when call evalStr() with undefined variable" do
820
940
  before do
821
941
  @nendo = Nendo::Core.new()
822
942
  end
823
943
  it "should" do
824
- lambda { @nendo.replStr( " true " ) }.should_not raise_error
825
- lambda { @nendo.replStr( " false " ) }.should_not raise_error
826
- lambda { @nendo.replStr( " nil " ) }.should_not raise_error
827
- lambda { @nendo.replStr( " line1 " ) }.should raise_error( NameError )
828
- lambda { @nendo.replStr( " true \n line2 " ) }.should raise_error( NameError )
829
- lambda { @nendo.replStr( " true \n true \n line3 " ) }.should raise_error( NameError )
830
- lambda { @nendo.replStr( " (+ 1 x) " ) }.should raise_error( NameError )
831
- lambda { @nendo.replStr( " true \n (+ 1 y) " ) }.should raise_error( NameError )
944
+ lambda { @nendo.evalStr( " true " ) }.should_not raise_error
945
+ lambda { @nendo.evalStr( " false " ) }.should_not raise_error
946
+ lambda { @nendo.evalStr( " nil " ) }.should_not raise_error
947
+ lambda { @nendo.evalStr( " line1 " ) }.should raise_error( NameError )
948
+ lambda { @nendo.evalStr( " true \n line2 " ) }.should raise_error( NameError )
949
+ lambda { @nendo.evalStr( " true \n true \n line3 " ) }.should raise_error( NameError )
950
+ lambda { @nendo.evalStr( " (+ 1 x) " ) }.should raise_error( NameError )
951
+ lambda { @nendo.evalStr( " true \n (+ 1 y) " ) }.should raise_error( NameError )
832
952
  end
833
953
  end
834
954
 
835
- describe Nendo, "when call replStr() with built-in special forms" do
955
+ describe Nendo, "when call evalStr() with built-in special forms" do
836
956
  before do
837
957
  @nendo = Nendo::Core.new()
838
958
  end
839
959
  it "should" do
840
- @nendo.replStr( " (begin 1) " ).should == "1"
841
- @nendo.replStr( " (begin 1 2) " ).should == "2"
842
- @nendo.replStr( " (begin 1 2 3) " ).should == "3"
843
- @nendo.replStr( " (set! x 2) (set! y (begin (set! x (* x 2)) (set! x (* x 2)) (set! x (* x 2)) 100)) (+ x y)" ).should == "116"
844
- @nendo.replStr( " (let () 100) " ).should == "100"
845
- @nendo.replStr( " (let ((a 11)) a) " ).should == "11"
846
- @nendo.replStr( " (let ((a 11) (b 22)) (+ a b)) " ).should == "33"
847
- @nendo.replStr( " (let ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
848
- @nendo.replStr( " (let ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
849
- @nendo.replStr( " (let ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
850
- @nendo.replStr( " (letrec () 100) " ).should == "100"
851
- @nendo.replStr( " (letrec ((a 11)) a) " ).should == "11"
852
- @nendo.replStr( " (letrec ((a 11) (b 22)) (+ a b)) " ).should == "33"
853
- @nendo.replStr( " (letrec ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
854
- @nendo.replStr( " (letrec ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
855
- @nendo.replStr( " (letrec ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
856
- @nendo.replStr( " (letrec ( (func1 (lambda (x) 13)) (func2 (lambda (x) (* 2 (func1)))) ) (list (func2) (func1))) " ).should == "(26 13)"
857
- @nendo.replStr( " (letrec ( (func2 (lambda (x) (* 2 (func1)))) (func1 (lambda (x) 7)) ) (list (func2) (func1))) " ).should == "(14 7)"
858
- @nendo.replStr( " (if true 't 'f)" ).should == "t"
859
- @nendo.replStr( " (if true '(1) '(2))" ).should == "(1)"
860
- @nendo.replStr( " (if false 't 'f)" ).should == "f"
861
- @nendo.replStr( " (if false '(1) '(2))" ).should == "(2)"
862
- @nendo.replStr( " (set! x 0) (if true (set! x 1) (set! x 2)) x" ).should == "1"
863
- @nendo.replStr( " (set! x 0) (if false (set! x 1) (set! x 2)) x" ).should == "2"
864
- @nendo.replStr( " (set! func (lambda (arg1) arg1)) (list (func 1) (func 2))" ).should == "(1 2)"
865
- @nendo.replStr( " ((lambda (arg1) arg1) 3)" ).should == "3"
866
- @nendo.replStr( " ((lambda (arg1) arg1) (+ 1 2 3))" ).should == "6"
867
- @nendo.replStr( " ((if #t + *) 3 4)" ).should == "7"
868
- @nendo.replStr( " ((if #f + *) 3 4)" ).should == "12"
869
- lambda { @nendo.replStr( " (error \"My Runtime Error\") " ) }.should raise_error( RuntimeError )
960
+ @nendo.evalStr( " (begin 1) " ).should == "1"
961
+ @nendo.evalStr( " (begin 1 2) " ).should == "2"
962
+ @nendo.evalStr( " (begin 1 2 3) " ).should == "3"
963
+ @nendo.evalStr( " (set! x 2) (set! y (begin (set! x (* x 2)) (set! x (* x 2)) (set! x (* x 2)) 100)) (+ x y)" ).should == "116"
964
+ @nendo.evalStr( " (let () 100) " ).should == "100"
965
+ @nendo.evalStr( " (let ((a 11)) a) " ).should == "11"
966
+ @nendo.evalStr( " (let ((a 11) (b 22)) (+ a b)) " ).should == "33"
967
+ @nendo.evalStr( " (let ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
968
+ @nendo.evalStr( " (let ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
969
+ @nendo.evalStr( " (let ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
970
+ @nendo.evalStr( " (letrec () 100) " ).should == "100"
971
+ @nendo.evalStr( " (letrec ((a 11)) a) " ).should == "11"
972
+ @nendo.evalStr( " (letrec ((a 11) (b 22)) (+ a b)) " ).should == "33"
973
+ @nendo.evalStr( " (letrec ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
974
+ @nendo.evalStr( " (letrec ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
975
+ @nendo.evalStr( " (letrec ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
976
+ @nendo.evalStr( " (letrec ( (func1 (lambda (x) 13)) (func2 (lambda (x) (* 2 (func1)))) ) (list (func2) (func1))) " ).should == "(26 13)"
977
+ @nendo.evalStr( " (letrec ( (func2 (lambda (x) (* 2 (func1)))) (func1 (lambda (x) 7)) ) (list (func2) (func1))) " ).should == "(14 7)"
978
+ @nendo.evalStr( " (if true 't 'f)" ).should == "t"
979
+ @nendo.evalStr( " (if true '(1) '(2))" ).should == "(1)"
980
+ @nendo.evalStr( " (if false 't 'f)" ).should == "f"
981
+ @nendo.evalStr( " (if false '(1) '(2))" ).should == "(2)"
982
+ @nendo.evalStr( " (set! x 0) (if true (set! x 1) (set! x 2)) x" ).should == "1"
983
+ @nendo.evalStr( " (set! x 0) (if false (set! x 1) (set! x 2)) x" ).should == "2"
984
+ @nendo.evalStr( " (set! func (lambda (arg1) arg1)) (list (func 1) (func 2))" ).should == "(1 2)"
985
+ @nendo.evalStr( " ((lambda (arg1) arg1) 3)" ).should == "3"
986
+ @nendo.evalStr( " ((lambda (arg1) arg1) (+ 1 2 3))" ).should == "6"
987
+ @nendo.evalStr( " ((if #t + *) 3 4)" ).should == "7"
988
+ @nendo.evalStr( " ((if #f + *) 3 4)" ).should == "12"
989
+ lambda { @nendo.evalStr( " (error \"My Runtime Error\") " ) }.should raise_error( RuntimeError )
870
990
  end
871
991
  end
872
992
 
873
- describe Nendo, "when call replStr() with global and lexical scope variable" do
993
+ describe Nendo, "when call evalStr() with global and lexical scope variable" do
874
994
  before do
875
995
  @nendo = Nendo::Core.new()
876
996
  end
877
997
  it "should" do
878
- @nendo.replStr( " (define var 111) " ).should == "111"
879
- @nendo.replStr( " (let ((var 222)) var) " ).should == "222"
880
- @nendo.replStr( " (let ((var 222)) (set! var 333) var) " ).should == "333"
881
- @nendo.replStr( " (let ((var 222)) (set! var 333)) var " ).should == "111"
882
- @nendo.replStr( " (define global1 \"G\") " ).should == '"G"'
883
- @nendo.replStr( " " +
998
+ @nendo.evalStr( " (define var 111) " ).should == "111"
999
+ @nendo.evalStr( " (let ((var 222)) var) " ).should == "222"
1000
+ @nendo.evalStr( " (let ((var 222)) (set! var 333) var) " ).should == "333"
1001
+ @nendo.evalStr( " (let ((var 222)) (set! var 333)) var " ).should == "111"
1002
+ @nendo.evalStr( " (define global1 \"G\") " ).should == '"G"'
1003
+ @nendo.evalStr( " " +
884
1004
  "(let ((local1 \"L\")" +
885
1005
  " (local2 \"L\"))" +
886
1006
  " (set! global1 (+ global1 \"lobal1\"))" +
@@ -899,24 +1019,24 @@ describe Nendo, "when call replStr() with global and lexical scope variable" do
899
1019
  end
900
1020
  end
901
1021
 
902
- describe Nendo, "when call replStr() with macroexpand-1 function" do
1022
+ describe Nendo, "when call evalStr() with macroexpand-1 function" do
903
1023
  before do
904
1024
  @nendo = Nendo::Core.new()
905
1025
  end
906
1026
  it "should" do
907
- @nendo.replStr( " (set! twice (macro (x) (list 'begin x x))) (macroexpand-1 '(twice (+ 1 1))) " ).should == "(begin (+ 1 1) (+ 1 1))"
908
- @nendo.replStr( " (set! inc (macro (x) (list 'set! x (list '+ x 1)))) (macroexpand-1 '(inc a)) " ).should == "(set! a (+ a 1))"
909
- @nendo.replStr( " (set! a 10) (inc a) " ).should == "11"
910
- @nendo.replStr( " (set! a 10) (inc a) (inc a)" ).should == "12"
911
- @nendo.replStr( " (macroexpand-1 '(twice (twice (inc a))))" ).should ==
1027
+ @nendo.evalStr( " (set! twice (macro (x) (list 'begin x x))) (macroexpand-1 '(twice (+ 1 1))) " ).should == "(begin (+ 1 1) (+ 1 1))"
1028
+ @nendo.evalStr( " (set! inc (macro (x) (list 'set! x (list '+ x 1)))) (macroexpand-1 '(inc a)) " ).should == "(set! a (+ a 1))"
1029
+ @nendo.evalStr( " (set! a 10) (inc a) " ).should == "11"
1030
+ @nendo.evalStr( " (set! a 10) (inc a) (inc a)" ).should == "12"
1031
+ @nendo.evalStr( " (macroexpand-1 '(twice (twice (inc a))))" ).should ==
912
1032
  "(begin (twice (inc a)) (twice (inc a)))"
913
- @nendo.replStr( " (macroexpand-1 (macroexpand-1 '(twice (twice (inc a)))))" ).should ==
1033
+ @nendo.evalStr( " (macroexpand-1 (macroexpand-1 '(twice (twice (inc a)))))" ).should ==
914
1034
  "(begin (begin (inc a) (inc a)) (begin (inc a) (inc a)))"
915
- @nendo.replStr( " (macroexpand-1 (macroexpand-1 (macroexpand-1 '(twice (twice (inc a))))))" ).should ==
1035
+ @nendo.evalStr( " (macroexpand-1 (macroexpand-1 (macroexpand-1 '(twice (twice (inc a))))))" ).should ==
916
1036
  "(begin (begin (set! a (+ a 1)) (set! a (+ a 1))) (begin (inc a) (inc a)))"
917
- @nendo.replStr( " (macroexpand-1 (macroexpand-1 (macroexpand-1 (macroexpand-1 '(twice (twice (inc a)))))))" ).should ==
1037
+ @nendo.evalStr( " (macroexpand-1 (macroexpand-1 (macroexpand-1 (macroexpand-1 '(twice (twice (inc a)))))))" ).should ==
918
1038
  "(begin (begin (set! a (+ a 1)) (set! a (+ a 1))) (begin (set! a (+ a 1)) (set! a (+ a 1))))"
919
- @nendo.replStr( " (set! a 10) (twice (twice (inc a)))" ).should == "14"
1039
+ @nendo.evalStr( " (set! a 10) (twice (twice (inc a)))" ).should == "14"
920
1040
  end
921
1041
  end
922
1042
 
@@ -927,168 +1047,170 @@ describe Nendo, "when call functions in init.nnd " do
927
1047
  @nendo.loadInitFile # to self optimizing. The init.nnd file will be loaded twice, so `map' can be optimized on second loading phase.
928
1048
  end
929
1049
  it "should" do
930
- @nendo.replStr( " (cadr '(1 2 3 4)) " ).should == "2"
931
- @nendo.replStr( " (caddr '(1 2 3 4)) " ).should == "3"
932
- @nendo.replStr( " (cadddr '(1 2 3 4)) " ).should == "4"
933
- @nendo.replStr( " (caar '((5 6 7 8))) " ).should == "5"
934
- @nendo.replStr( " (cdar '((5 6 7 8))) " ).should == "(6 7 8)"
935
- @nendo.replStr( " (cadar '((5 6 7 8))) " ).should == "6"
936
- @nendo.replStr( " (cddar '((5 6 7 8))) " ).should == "(7 8)"
937
- @nendo.replStr( " (iota 1) " ).should == "(0)"
938
- @nendo.replStr( " (iota 3) " ).should == "(0 1 2)"
939
- @nendo.replStr( " (append '() '()) " ).should == "()"
940
- @nendo.replStr( " (append '(1) '()) " ).should == "(1)"
941
- @nendo.replStr( " (append '() '(2)) " ).should == "(2)"
942
- @nendo.replStr( " (append '(1) '(2)) " ).should == "(1 2)"
943
- @nendo.replStr( " (append '(1 2) '(3 4)) " ).should == "(1 2 3 4)"
944
- @nendo.replStr( " (pair? '()) " ).should == "#f"
945
- @nendo.replStr( " (pair? '(1)) " ).should == "#t"
946
- @nendo.replStr( " (pair? '(1 2)) " ).should == "#t"
947
- @nendo.replStr( " (pair? '(1 2 3)) " ).should == "#t"
948
- @nendo.replStr( " (pair? '(1 . 2)) " ).should == "#t"
949
- @nendo.replStr( " (pair? '(())) " ).should == "#t"
950
- @nendo.replStr( " (pair? 1) " ).should == "#f"
951
- @nendo.replStr( " (pair? \"str\") " ).should == "#f"
952
- @nendo.replStr( " (list? '()) " ).should == "#t"
953
- @nendo.replStr( " (list? '(1)) " ).should == "#t"
954
- @nendo.replStr( " (list? '(1 2)) " ).should == "#t"
955
- @nendo.replStr( " (list? '(1 2 3)) " ).should == "#t"
956
- @nendo.replStr( " (list? '(1 . 2)) " ).should == "#f"
957
- @nendo.replStr( " (list? '(1 2 . 3)) " ).should == "#f"
958
- @nendo.replStr( " (list? '(())) " ).should == "#t"
959
- @nendo.replStr( " (list? 1) " ).should == "#f"
960
- @nendo.replStr( " (list? \"str\") " ).should == "#f"
961
- @nendo.replStr( " (even? 2) " ).should == "#t"
962
- @nendo.replStr( " (even? 1) " ).should == "#f"
963
- @nendo.replStr( " (even? 0) " ).should == "#t"
964
- @nendo.replStr( " (even? -1) " ).should == "#f"
965
- @nendo.replStr( " (even? -2) " ).should == "#t"
966
- @nendo.replStr( " (odd? 2) " ).should == "#f"
967
- @nendo.replStr( " (odd? 1) " ).should == "#t"
968
- @nendo.replStr( " (odd? 0) " ).should == "#f"
969
- @nendo.replStr( " (odd? -1) " ).should == "#t"
970
- @nendo.replStr( " (odd? -2) " ).should == "#f"
971
- @nendo.replStr( " (zero? 0) " ).should == "#t"
972
- @nendo.replStr( " (zero? #f) " ).should == "#f"
973
- @nendo.replStr( " (zero? #t) " ).should == "#f"
974
- @nendo.replStr( " (zero? 1) " ).should == "#f"
975
- @nendo.replStr( " (zero? 2) " ).should == "#f"
976
- @nendo.replStr( " (zero? -1) " ).should == "#f"
977
- @nendo.replStr( " (zero? \"str\") " ).should == "#f"
978
- @nendo.replStr( " (zero? zero?) " ).should == "#f"
979
- @nendo.replStr( " (positive? 1) " ).should == "#t"
980
- @nendo.replStr( " (positive? 0) " ).should == "#f"
981
- @nendo.replStr( " (positive? -1) " ).should == "#f"
982
- @nendo.replStr( " (negative? 1) " ).should == "#f"
983
- @nendo.replStr( " (negative? 0) " ).should == "#f"
984
- @nendo.replStr( " (negative? -1) " ).should == "#t"
985
- @nendo.replStr( " (abs -1) " ).should == "1"
986
- @nendo.replStr( " (abs 1) " ).should == "1"
987
- @nendo.replStr( " (abs -1000) " ).should == "1000"
988
- @nendo.replStr( " (abs 1000) " ).should == "1000"
989
- @nendo.replStr( " (max -2 1 0 1 2 3 4 5) " ).should == "5"
990
- @nendo.replStr( " (max 5 4 3 2 1 0 -1 -2) " ).should == "5"
991
- @nendo.replStr( " (max 1000000000 10 -10000) " ).should == "1000000000"
992
- @nendo.replStr( " (min -2 1 0 1 2 3 4 5) " ).should == "-2"
993
- @nendo.replStr( " (min 5 4 3 2 1 0 -1 -2) " ).should == "-2"
994
- @nendo.replStr( " (min 1000000000 10 -10000) " ).should == "-10000"
995
- @nendo.replStr( " (succ -1) " ).should == "0"
996
- @nendo.replStr( " (succ 0) " ).should == "1"
997
- @nendo.replStr( " (succ 1) " ).should == "2"
998
- @nendo.replStr( " (pred -1) " ).should == "-2"
999
- @nendo.replStr( " (pred 0) " ).should == "-1"
1000
- @nendo.replStr( " (pred 1) " ).should == "0"
1001
- @nendo.replStr( " (pred 2) " ).should == "1"
1002
- @nendo.replStr( " (min 1000000000 10 -10000) " ).should == "-10000"
1003
- @nendo.replStr( " (nth 0 '(100 200 300)) " ).should == "100"
1004
- @nendo.replStr( " (nth 1 '(100 200 300)) " ).should == "200"
1005
- @nendo.replStr( " (nth 2 '(100 200 300)) " ).should == "300"
1006
- @nendo.replStr( " (nth 3 '(100 200 300)) " ).should == "()"
1007
- @nendo.replStr( " (nth -1 '(100 200 300)) " ).should == "()"
1008
- @nendo.replStr( " (first '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "100"
1009
- @nendo.replStr( " (second '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "200"
1010
- @nendo.replStr( " (third '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "300"
1011
- @nendo.replStr( " (fourth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "400"
1012
- @nendo.replStr( " (fifth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "500"
1013
- @nendo.replStr( " (sixth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "600"
1014
- @nendo.replStr( " (seventh '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "700"
1015
- @nendo.replStr( " (eighth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "800"
1016
- @nendo.replStr( " (ninth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "900"
1017
- @nendo.replStr( " (tenth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "1000"
1018
- @nendo.replStr( " (first '()) " ).should == "()"
1019
- @nendo.replStr( " (tenth '()) " ).should == "()"
1020
- @nendo.replStr( " (to-s 10) " ).should == '"10"'
1021
- @nendo.replStr( " (to_s 10) " ).should == '"10"'
1022
- @nendo.replStr( " (x->string 10) " ).should == '"10"'
1023
- @nendo.replStr( " (to-s 2.1) " ).should == '"2.1"'
1024
- @nendo.replStr( " (to_s 2.1) " ).should == '"2.1"'
1025
- @nendo.replStr( " (x->string 2.1) " ).should == '"2.1"'
1026
- @nendo.replStr( " (to_i \"22\") " ).should == '22'
1027
- @nendo.replStr( " (to-i \"22\") " ).should == '22'
1028
- @nendo.replStr( " (to_i \"10000\") " ).should == '10000'
1029
- @nendo.replStr( " (to-i \"10000\") " ).should == '10000'
1030
- @nendo.replStr( " (let1 aaa 111 aaa) " ).should == "111"
1031
- @nendo.replStr( " (let1 aaa (+ 2 3) aaa) " ).should == "5"
1032
- @nendo.replStr( " (let1 aaa 333 (let1 bbb 444 (+ aaa bbb))) " ).should == "777"
1033
- @nendo.replStr( " (let1 aaa 333 (let1 bbb 444 (set! bbb 555) (+ aaa bbb))) " ).should == "888"
1034
- @nendo.replStr( " (let1 v (map (lambda (x) x) '(1 2 3)) v) " ).should == "(1 2 3)"
1035
- @nendo.replStr( " (let ((v (map (lambda (x) x) '(1 2 3)))) v) " ).should == "(1 2 3)"
1036
- @nendo.replStr( " (cond (true 1) (false 2)) " ).should == "1"
1037
- @nendo.replStr( " (cond (true ) (false )) " ).should == "#t"
1038
- @nendo.replStr( " (cond (false 1) (true 2)) " ).should == "2"
1039
- @nendo.replStr( " (cond (true 1) (true 2)) " ).should == "1"
1040
- @nendo.replStr( " (cond (false 1) (false 2)) " ).should == "()"
1041
- @nendo.replStr( " (cond (false 1) (false 2) (else 3)) " ).should == "3"
1042
- @nendo.replStr( " (cond ((- 10 9) => (lambda (x) (+ \"<\" (to_s x) \">\"))) (else 2)) " ).should == '"<1>"'
1043
- @nendo.replStr( " (cond (true 1) ((- 10 8) => (lambda (x) (+ \"<\" (to_s x) \">\"))) (else 3)) " ).should == "1"
1044
- @nendo.replStr( " (or) " ).should == "#f"
1045
- @nendo.replStr( " (or true) " ).should == "#t"
1046
- @nendo.replStr( " (or false) " ).should == "#f"
1047
- @nendo.replStr( " (or nil) " ).should == "#f"
1048
- @nendo.replStr( " (or '(1)) " ).should == "(1)"
1049
- @nendo.replStr( " (or '()) " ).should == "()"
1050
- @nendo.replStr( " (or true true true) " ).should == "#t"
1051
- @nendo.replStr( " (or 1 2 3) " ).should == "1"
1052
- @nendo.replStr( " (or false 2) " ).should == "2"
1053
- @nendo.replStr( " (or false false 3) " ).should == "3"
1054
- @nendo.replStr( " (or false '(2) false) " ).should == "(2)"
1055
- @nendo.replStr( " (and) " ).should == "#t"
1056
- @nendo.replStr( " (and true) " ).should == "#t"
1057
- @nendo.replStr( " (and false) " ).should == "#f"
1058
- @nendo.replStr( " (and nil) " ).should == "nil"
1059
- @nendo.replStr( " (and '(1)) " ).should == "(1)"
1060
- @nendo.replStr( " (and '()) " ).should == "()"
1061
- @nendo.replStr( " (and true true true) " ).should == "#t"
1062
- @nendo.replStr( " (and 1 2 3) " ).should == "3"
1063
- @nendo.replStr( " (and false 2) " ).should == "#f"
1064
- @nendo.replStr( " (and false false 3) " ).should == "#f"
1065
- @nendo.replStr( " (and true 2) " ).should == "2"
1066
- @nendo.replStr( " (and true true 3) " ).should == "3"
1067
- @nendo.replStr( " (and true true 3 false) " ).should == "#f"
1068
- @nendo.replStr( " (and true '(2) true) " ).should == "#t"
1069
- @nendo.replStr( " (and true true '(2)) " ).should == "(2)"
1070
- @nendo.replStr( " (and true '(2) false) " ).should == "#f"
1071
- @nendo.replStr( " (define total 0) (and 1 2 (set! total (+ total 1)) (set! total (+ total 2)) 5) total" ).should == "3"
1072
- @nendo.replStr( " (define total 1) (and 1 2 false (set! total (+ total 2)) (set! total (+ total 3)) 5) total" ).should == "1"
1073
- @nendo.replStr( " (apply + 100 '()) " ).should == "100"
1074
- @nendo.replStr( " (apply + '(1 2)) " ).should == "3"
1075
- @nendo.replStr( " (apply + 1 2 '(3)) " ).should == "6"
1076
- @nendo.replStr( " (apply + 1 2 '(3 4)) " ).should == "10"
1077
- @nendo.replStr( " (apply + 1 2 3 '(4)) " ).should == "10"
1078
- @nendo.replStr( ' (apply + \'("a" "b" "c")) ' ).should == '"abc"'
1079
- @nendo.replStr( " (range 5) " ).should == "(0 1 2 3 4)"
1080
- @nendo.replStr( " (range 5 1) " ).should == "(1 2 3 4 5)"
1081
- @nendo.replStr( " (range 5 2) " ).should == "(2 3 4 5 6)"
1082
- @nendo.replStr( " (iota 5 2) " ).should == "(2 3 4 5 6)"
1083
- @nendo.replStr( " (apply + (range 11)) " ).should == "55"
1084
- @nendo.replStr( " (apply + (map (lambda (x) (+ x 1)) (range 10))) " ).should == "55"
1085
- @nendo.replStr( " (apply + (append (range 11) '(100))) " ).should == "155"
1086
- @nendo.replStr( " (map (lambda (x) (* x 2)) '(1 2 3)) " ).should == "(2 4 6)"
1087
- @nendo.replStr( " (map (lambda (x) (+ x 1)) '(1 2 3)) " ).should == "(2 3 4)"
1088
- @nendo.replStr( " (map (lambda (a b) (+ a b)) '(1 2 3) '(10 20 30)) " ).should == "(11 22 33)"
1089
- @nendo.replStr( " (map (lambda (a b) (- b a)) '(1 2 3) '(10 20 30)) " ).should == "(9 18 27)"
1090
- @nendo.replStr( " (map (lambda (a b c) (+ a b c)) '(1 2 3) '(10 20 30) '(100 200 300)) " ).should == "(111 222 333)"
1091
- @nendo.replStr( " (define _result"+
1050
+ @nendo.evalStr( " (cadr '(1 2 3 4)) " ).should == "2"
1051
+ @nendo.evalStr( " (caddr '(1 2 3 4)) " ).should == "3"
1052
+ @nendo.evalStr( " (cadddr '(1 2 3 4)) " ).should == "4"
1053
+ @nendo.evalStr( " (caar '((5 6 7 8))) " ).should == "5"
1054
+ @nendo.evalStr( " (cdar '((5 6 7 8))) " ).should == "(6 7 8)"
1055
+ @nendo.evalStr( " (cadar '((5 6 7 8))) " ).should == "6"
1056
+ @nendo.evalStr( " (cddar '((5 6 7 8))) " ).should == "(7 8)"
1057
+ @nendo.evalStr( " (iota 1) " ).should == "(0)"
1058
+ @nendo.evalStr( " (iota 3) " ).should == "(0 1 2)"
1059
+ @nendo.evalStr( " (append '() '()) " ).should == "()"
1060
+ @nendo.evalStr( " (append '(1) '()) " ).should == "(1)"
1061
+ @nendo.evalStr( " (append '() '(2)) " ).should == "(2)"
1062
+ @nendo.evalStr( " (append '(1) '(2)) " ).should == "(1 2)"
1063
+ @nendo.evalStr( " (append '(1 2) '(3 4)) " ).should == "(1 2 3 4)"
1064
+ @nendo.evalStr( " (pair? '()) " ).should == "#f"
1065
+ @nendo.evalStr( " (pair? '(1)) " ).should == "#t"
1066
+ @nendo.evalStr( " (pair? '(1 2)) " ).should == "#t"
1067
+ @nendo.evalStr( " (pair? '(1 2 3)) " ).should == "#t"
1068
+ @nendo.evalStr( " (pair? '(1 . 2)) " ).should == "#t"
1069
+ @nendo.evalStr( " (pair? '(())) " ).should == "#t"
1070
+ @nendo.evalStr( " (pair? 1) " ).should == "#f"
1071
+ @nendo.evalStr( " (pair? \"str\") " ).should == "#f"
1072
+ @nendo.evalStr( " (list? '()) " ).should == "#t"
1073
+ @nendo.evalStr( " (list? '(1)) " ).should == "#t"
1074
+ @nendo.evalStr( " (list? '(1 2)) " ).should == "#t"
1075
+ @nendo.evalStr( " (list? '(1 2 3)) " ).should == "#t"
1076
+ @nendo.evalStr( " (list? '(1 . 2)) " ).should == "#f"
1077
+ @nendo.evalStr( " (list? '(1 2 . 3)) " ).should == "#f"
1078
+ @nendo.evalStr( " (list? '(())) " ).should == "#t"
1079
+ @nendo.evalStr( " (list? 1) " ).should == "#f"
1080
+ @nendo.evalStr( " (list? \"str\") " ).should == "#f"
1081
+ @nendo.evalStr( " (even? 2) " ).should == "#t"
1082
+ @nendo.evalStr( " (even? 1) " ).should == "#f"
1083
+ @nendo.evalStr( " (even? 0) " ).should == "#t"
1084
+ @nendo.evalStr( " (even? -1) " ).should == "#f"
1085
+ @nendo.evalStr( " (even? -2) " ).should == "#t"
1086
+ @nendo.evalStr( " (odd? 2) " ).should == "#f"
1087
+ @nendo.evalStr( " (odd? 1) " ).should == "#t"
1088
+ @nendo.evalStr( " (odd? 0) " ).should == "#f"
1089
+ @nendo.evalStr( " (odd? -1) " ).should == "#t"
1090
+ @nendo.evalStr( " (odd? -2) " ).should == "#f"
1091
+ @nendo.evalStr( " (zero? 0) " ).should == "#t"
1092
+ @nendo.evalStr( " (zero? #f) " ).should == "#f"
1093
+ @nendo.evalStr( " (zero? #t) " ).should == "#f"
1094
+ @nendo.evalStr( " (zero? 1) " ).should == "#f"
1095
+ @nendo.evalStr( " (zero? 2) " ).should == "#f"
1096
+ @nendo.evalStr( " (zero? -1) " ).should == "#f"
1097
+ @nendo.evalStr( " (zero? \"str\") " ).should == "#f"
1098
+ @nendo.evalStr( " (zero? zero?) " ).should == "#f"
1099
+ @nendo.evalStr( " (positive? 1) " ).should == "#t"
1100
+ @nendo.evalStr( " (positive? 0) " ).should == "#f"
1101
+ @nendo.evalStr( " (positive? -1) " ).should == "#f"
1102
+ @nendo.evalStr( " (negative? 1) " ).should == "#f"
1103
+ @nendo.evalStr( " (negative? 0) " ).should == "#f"
1104
+ @nendo.evalStr( " (negative? -1) " ).should == "#t"
1105
+ @nendo.evalStr( " (abs -1) " ).should == "1"
1106
+ @nendo.evalStr( " (abs 1) " ).should == "1"
1107
+ @nendo.evalStr( " (abs -1000) " ).should == "1000"
1108
+ @nendo.evalStr( " (abs 1000) " ).should == "1000"
1109
+ @nendo.evalStr( " (max -2 1 0 1 2 3 4 5) " ).should == "5"
1110
+ @nendo.evalStr( " (max 5 4 3 2 1 0 -1 -2) " ).should == "5"
1111
+ @nendo.evalStr( " (max 1000000000 10 -10000) " ).should == "1000000000"
1112
+ @nendo.evalStr( " (min -2 1 0 1 2 3 4 5) " ).should == "-2"
1113
+ @nendo.evalStr( " (min 5 4 3 2 1 0 -1 -2) " ).should == "-2"
1114
+ @nendo.evalStr( " (min 1000000000 10 -10000) " ).should == "-10000"
1115
+ @nendo.evalStr( " (succ -1) " ).should == "0"
1116
+ @nendo.evalStr( " (succ 0) " ).should == "1"
1117
+ @nendo.evalStr( " (succ 1) " ).should == "2"
1118
+ @nendo.evalStr( " (pred -1) " ).should == "-2"
1119
+ @nendo.evalStr( " (pred 0) " ).should == "-1"
1120
+ @nendo.evalStr( " (pred 1) " ).should == "0"
1121
+ @nendo.evalStr( " (pred 2) " ).should == "1"
1122
+ @nendo.evalStr( " (min 1000000000 10 -10000) " ).should == "-10000"
1123
+ @nendo.evalStr( " (nth 0 '(100 200 300)) " ).should == "100"
1124
+ @nendo.evalStr( " (nth 1 '(100 200 300)) " ).should == "200"
1125
+ @nendo.evalStr( " (nth 2 '(100 200 300)) " ).should == "300"
1126
+ @nendo.evalStr( " (nth 3 '(100 200 300)) " ).should == "()"
1127
+ @nendo.evalStr( " (nth -1 '(100 200 300)) " ).should == "()"
1128
+ @nendo.evalStr( " (first '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "100"
1129
+ @nendo.evalStr( " (second '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "200"
1130
+ @nendo.evalStr( " (third '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "300"
1131
+ @nendo.evalStr( " (fourth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "400"
1132
+ @nendo.evalStr( " (fifth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "500"
1133
+ @nendo.evalStr( " (sixth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "600"
1134
+ @nendo.evalStr( " (seventh '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "700"
1135
+ @nendo.evalStr( " (eighth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "800"
1136
+ @nendo.evalStr( " (ninth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "900"
1137
+ @nendo.evalStr( " (tenth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "1000"
1138
+ @nendo.evalStr( " (first '()) " ).should == "()"
1139
+ @nendo.evalStr( " (tenth '()) " ).should == "()"
1140
+ @nendo.evalStr( " (to-s 10) " ).should == '"10"'
1141
+ @nendo.evalStr( " (to_s 10) " ).should == '"10"'
1142
+ @nendo.evalStr( " (x->string 10) " ).should == '"10"'
1143
+ @nendo.evalStr( " (to-s 2.1) " ).should == '"2.1"'
1144
+ @nendo.evalStr( " (to_s 2.1) " ).should == '"2.1"'
1145
+ @nendo.evalStr( " (x->string 2.1) " ).should == '"2.1"'
1146
+ @nendo.evalStr( " (to_i \"22\") " ).should == '22'
1147
+ @nendo.evalStr( " (to-i \"22\") " ).should == '22'
1148
+ @nendo.evalStr( " (to_i \"10000\") " ).should == '10000'
1149
+ @nendo.evalStr( " (to-i \"10000\") " ).should == '10000'
1150
+ @nendo.evalStr( " (let1 aaa 111 aaa) " ).should == "111"
1151
+ @nendo.evalStr( " (let1 aaa (+ 2 3) aaa) " ).should == "5"
1152
+ @nendo.evalStr( " (let1 aaa 333 (let1 bbb 444 (+ aaa bbb))) " ).should == "777"
1153
+ @nendo.evalStr( " (let1 aaa 333 (let1 bbb 444 (set! bbb 555) (+ aaa bbb))) " ).should == "888"
1154
+ @nendo.evalStr( " (let1 v (map (lambda (x) x) '(1 2 3)) v) " ).should == "(1 2 3)"
1155
+ @nendo.evalStr( " (let ((v (map (lambda (x) x) '(1 2 3)))) v) " ).should == "(1 2 3)"
1156
+ @nendo.evalStr( " (cond (true 1) (false 2)) " ).should == "1"
1157
+ @nendo.evalStr( " (cond (true ) (false )) " ).should == "#t"
1158
+ @nendo.evalStr( " (cond (false 1) (true 2)) " ).should == "2"
1159
+ @nendo.evalStr( " (cond (true 1) (true 2)) " ).should == "1"
1160
+ @nendo.evalStr( " (cond (false 1) (false 2)) " ).should == "()"
1161
+ @nendo.evalStr( " (cond (false 1) (false 2) (else 3)) " ).should == "3"
1162
+ @nendo.evalStr( " (cond ((- 10 9) => (lambda (x) (+ \"<\" (to_s x) \">\"))) (else 2)) " ).should == '"<1>"'
1163
+ @nendo.evalStr( " (cond (true 1) ((- 10 8) => (lambda (x) (+ \"<\" (to_s x) \">\"))) (else 3)) " ).should == "1"
1164
+ @nendo.evalStr( " (or) " ).should == "#f"
1165
+ @nendo.evalStr( " (or true) " ).should == "#t"
1166
+ @nendo.evalStr( " (or false) " ).should == "#f"
1167
+ @nendo.evalStr( " (or nil) " ).should == "#f"
1168
+ @nendo.evalStr( " (or '(1)) " ).should == "(1)"
1169
+ @nendo.evalStr( " (or '()) " ).should == "()"
1170
+ @nendo.evalStr( " (or true true true) " ).should == "#t"
1171
+ @nendo.evalStr( " (or 1 2 3) " ).should == "1"
1172
+ @nendo.evalStr( " (or false 2) " ).should == "2"
1173
+ @nendo.evalStr( " (or false false 3) " ).should == "3"
1174
+ @nendo.evalStr( " (or false '(2) false) " ).should == "(2)"
1175
+ @nendo.evalStr( " (and) " ).should == "#t"
1176
+ @nendo.evalStr( " (and true) " ).should == "#t"
1177
+ @nendo.evalStr( " (and false) " ).should == "#f"
1178
+ @nendo.evalStr( " (and nil) " ).should == "nil"
1179
+ @nendo.evalStr( " (and '(1)) " ).should == "(1)"
1180
+ @nendo.evalStr( " (and '()) " ).should == "()"
1181
+ @nendo.evalStr( " (and true true true) " ).should == "#t"
1182
+ @nendo.evalStr( " (and 1 2 3) " ).should == "3"
1183
+ @nendo.evalStr( " (and false 2) " ).should == "#f"
1184
+ @nendo.evalStr( " (and false false 3) " ).should == "#f"
1185
+ @nendo.evalStr( " (and true 2) " ).should == "2"
1186
+ @nendo.evalStr( " (and true true 3) " ).should == "3"
1187
+ @nendo.evalStr( " (and true true 3 false) " ).should == "#f"
1188
+ @nendo.evalStr( " (and true '(2) true) " ).should == "#t"
1189
+ @nendo.evalStr( " (and true true '(2)) " ).should == "(2)"
1190
+ @nendo.evalStr( " (and true '(2) false) " ).should == "#f"
1191
+ @nendo.evalStr( " (define total 0) (and 1 2 (set! total (+ total 1)) (set! total (+ total 2)) 5) total" ).should == "3"
1192
+ @nendo.evalStr( " (define total 1) (and 1 2 false (set! total (+ total 2)) (set! total (+ total 3)) 5) total" ).should == "1"
1193
+ @nendo.evalStr( " (apply + 100 '()) " ).should == "100"
1194
+ @nendo.evalStr( " (apply + '(1 2)) " ).should == "3"
1195
+ @nendo.evalStr( " (apply + 1 2 '(3)) " ).should == "6"
1196
+ @nendo.evalStr( " (apply + 1 2 '(3 4)) " ).should == "10"
1197
+ @nendo.evalStr( " (apply + 1 2 3 '(4)) " ).should == "10"
1198
+ @nendo.evalStr( ' (apply + \'("a" "b" "c")) ' ).should == '"abc"'
1199
+ @nendo.evalStr( " (range 5) " ).should == "(0 1 2 3 4)"
1200
+ @nendo.evalStr( " (range 5 1) " ).should == "(1 2 3 4 5)"
1201
+ @nendo.evalStr( " (range 5 2) " ).should == "(2 3 4 5 6)"
1202
+ @nendo.evalStr( " (iota 5 2) " ).should == "(2 3 4 5 6)"
1203
+ @nendo.evalStr( " (apply + (range 11)) " ).should == "55"
1204
+ @nendo.evalStr( " (apply + (map (lambda (x) (+ x 1)) (range 10))) " ).should == "55"
1205
+ @nendo.evalStr( " (apply + (append (range 11) '(100))) " ).should == "155"
1206
+ @nendo.evalStr( " (map (lambda (x) 1) '()) " ).should == "()"
1207
+ @nendo.evalStr( " (map (lambda (x) 1) (to-list '#())) " ).should == "()"
1208
+ @nendo.evalStr( " (map (lambda (x) (* x 2)) '(1 2 3)) " ).should == "(2 4 6)"
1209
+ @nendo.evalStr( " (map (lambda (x) (+ x 1)) '(1 2 3)) " ).should == "(2 3 4)"
1210
+ @nendo.evalStr( " (map (lambda (a b) (+ a b)) '(1 2 3) '(10 20 30)) " ).should == "(11 22 33)"
1211
+ @nendo.evalStr( " (map (lambda (a b) (- b a)) '(1 2 3) '(10 20 30)) " ).should == "(9 18 27)"
1212
+ @nendo.evalStr( " (map (lambda (a b c) (+ a b c)) '(1 2 3) '(10 20 30) '(100 200 300)) " ).should == "(111 222 333)"
1213
+ @nendo.evalStr( " (define _result"+
1092
1214
  " (map"+
1093
1215
  " (lambda (x)"+
1094
1216
  " (* x 2))"+
@@ -1097,32 +1219,35 @@ describe Nendo, "when call functions in init.nnd " do
1097
1219
  " (first _result)"+
1098
1220
  " (second _result)"+
1099
1221
  " (last-pair _result))" ).should == "(2 4 (20000))"
1100
- @nendo.replStr( " (define _lst '()) (for-each (lambda (x) (set! _lst (cons (* x 2) _lst))) '(1 2 3)) _lst" ).should == "(6 4 2)"
1101
- @nendo.replStr( " (define _lst '()) (for-each (lambda (x) (set! _lst (cons (+ x 1) _lst))) '(1 2 3)) _lst" ).should == "(4 3 2)"
1102
- @nendo.replStr( " (define _lst '()) (for-each (lambda (a b) (set! _lst (cons (cons a b) _lst))) '(1 2 3) '(10 20 30)) _lst" ).should ==
1222
+ @nendo.evalStr( " (define _lst '()) (for-each (lambda (x) (set! _lst (cons 1 _lst))) '()) _lst" ).should == "()"
1223
+ @nendo.evalStr( " (define _lst '()) (for-each (lambda (x) (set! _lst (cons (* x 2) _lst))) '(1 2 3)) _lst" ).should == "(6 4 2)"
1224
+ @nendo.evalStr( " (define _lst '()) (for-each (lambda (x) (set! _lst (cons (+ x 1) _lst))) '(1 2 3)) _lst" ).should == "(4 3 2)"
1225
+ @nendo.evalStr( " (define _lst '()) (for-each (lambda (a b) (set! _lst (cons (cons a b) _lst))) '(1 2 3) '(10 20 30)) _lst" ).should ==
1103
1226
  "((3 . 30) (2 . 20) (1 . 10))"
1104
- @nendo.replStr( " (define _cnt 0) (for-each (lambda (x) (set! _cnt (+ _cnt 1))) (range 10000)) _cnt" ).should == "10000"
1105
- @nendo.replStr( " (filter (lambda (x) (= x 100)) '(1 2 3)) " ).should == "()"
1106
- @nendo.replStr( " (filter (lambda (x) (= x 2)) '(1 2 3)) " ).should == "(2)"
1107
- @nendo.replStr( " (filter (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "(1 3)"
1108
- @nendo.replStr( " (filter (lambda (x) (if (= x 2) (* x 100) false)) '(1 2 3)) " ).should == "(2)"
1109
- @nendo.replStr( " (find (lambda (x) (= x 100)) '(1 2 3)) " ).should == "#f"
1110
- @nendo.replStr( " (find (lambda (x) (= x 2)) '(1 2 3)) " ).should == "2"
1111
- @nendo.replStr( " (find (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "1"
1112
- @nendo.replStr( " (find (lambda (x) (if (= x 2) (* x 100) false)) '(1 2 3)) " ).should == "2"
1113
- @nendo.replStr( " (filter-map (lambda (x) (= x 100)) '(1 2 3)) " ).should == "()"
1114
- @nendo.replStr( " (filter-map (lambda (x) (= x 2)) '(1 2 3)) " ).should == "(#t)"
1115
- @nendo.replStr( " (filter-map (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "(#t #t)"
1116
- @nendo.replStr( " (filter-map (lambda (x) (if (= x 2) (* x 10) false)) '(1 2 3)) " ).should == "(20)"
1117
- @nendo.replStr( " (filter-map (lambda (x) (if (not (= x 2)) (* x 10) false)) '(1 2 3)) " ).should == "(10 30)"
1118
- @nendo.replStr( " " +
1227
+ @nendo.evalStr( " (define _cnt 0) (for-each (lambda (x) (set! _cnt (+ _cnt 1))) (range 10000)) _cnt" ).should == "10000"
1228
+ @nendo.evalStr( " (filter (lambda (x) x) '()) " ).should == "()"
1229
+ @nendo.evalStr( " (filter (lambda (x) (= x 100)) '(1 2 3)) " ).should == "()"
1230
+ @nendo.evalStr( " (filter (lambda (x) (= x 2)) '(1 2 3)) " ).should == "(2)"
1231
+ @nendo.evalStr( " (filter (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "(1 3)"
1232
+ @nendo.evalStr( " (filter (lambda (x) (if (= x 2) (* x 100) false)) '(1 2 3)) " ).should == "(2)"
1233
+ @nendo.evalStr( " (find (lambda (x) (= x 100)) '(1 2 3)) " ).should == "#f"
1234
+ @nendo.evalStr( " (find (lambda (x) (= x 2)) '(1 2 3)) " ).should == "2"
1235
+ @nendo.evalStr( " (find (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "1"
1236
+ @nendo.evalStr( " (find (lambda (x) (if (= x 2) (* x 100) false)) '(1 2 3)) " ).should == "2"
1237
+ @nendo.evalStr( " (filter-map (lambda (x) x) '()) " ).should == "()"
1238
+ @nendo.evalStr( " (filter-map (lambda (x) (= x 100)) '(1 2 3)) " ).should == "()"
1239
+ @nendo.evalStr( " (filter-map (lambda (x) (= x 2)) '(1 2 3)) " ).should == "(#t)"
1240
+ @nendo.evalStr( " (filter-map (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "(#t #t)"
1241
+ @nendo.evalStr( " (filter-map (lambda (x) (if (= x 2) (* x 10) false)) '(1 2 3)) " ).should == "(20)"
1242
+ @nendo.evalStr( " (filter-map (lambda (x) (if (not (= x 2)) (* x 10) false)) '(1 2 3)) " ).should == "(10 30)"
1243
+ @nendo.evalStr( " " +
1119
1244
  "(let1 result '()" +
1120
1245
  " (do" +
1121
1246
  " ((i 0 (+ i 1)))" +
1122
1247
  " ((< 10 i) #f)" +
1123
1248
  " (set! result (cons i result)))" +
1124
1249
  " (reverse result))" ).should == "(0 1 2 3 4 5 6 7 8 9 10)"
1125
- @nendo.replStr( " " +
1250
+ @nendo.evalStr( " " +
1126
1251
  "(let1 result '()" +
1127
1252
  " (do" +
1128
1253
  " ((i 0 (+ i 3)))" +
@@ -1138,57 +1263,57 @@ describe Nendo, "when use values " do
1138
1263
  @nendo.loadInitFile
1139
1264
  end
1140
1265
  it "should" do
1141
- @nendo.replStr( " (values? (make-values '())) " ).should == "#t"
1142
- lambda { @nendo.replStr( " (make-values '(1))) " ) }.should raise_error(ArgumentError)
1143
- @nendo.replStr( " (values? (make-values '(1 2))) " ).should == "#t"
1144
- @nendo.replStr( " (values? (make-values '(1 2 3))) " ).should == "#t"
1145
- @nendo.replStr( " (values? (values)) " ).should == "#t"
1146
- @nendo.replStr( " (values? (values 1)) " ).should == "#f"
1147
- @nendo.replStr( " (values 1) " ).should == "1"
1148
- @nendo.replStr( " (values? (values 1 2)) " ).should == "#t"
1149
- @nendo.replStr( " (values? (values 1 2 3)) " ).should == "#t"
1150
- @nendo.replStr( " (values? (values '(a) \"b\" '(\"C\"))) " ).should == "#t"
1151
- @nendo.replStr( " (values-values (values)) " ).should == "()"
1152
- lambda { @nendo.replStr( " (values-values (values 1)) " ) }.should raise_error(TypeError)
1153
- @nendo.replStr( " (values-values (values 1 2)) " ).should == "(1 2)"
1154
- @nendo.replStr( " (values-values (values 1 2 3)) " ).should == "(1 2 3)"
1155
- @nendo.replStr( " (values-values (values '(a) \"b\" '(\"C\"))) " ).should == '((a) "b" ("C"))'
1156
- @nendo.replStr( "" +
1266
+ @nendo.evalStr( " (values? (make-values '())) " ).should == "#t"
1267
+ lambda { @nendo.evalStr( " (make-values '(1))) " ) }.should raise_error(ArgumentError)
1268
+ @nendo.evalStr( " (values? (make-values '(1 2))) " ).should == "#t"
1269
+ @nendo.evalStr( " (values? (make-values '(1 2 3))) " ).should == "#t"
1270
+ @nendo.evalStr( " (values? (values)) " ).should == "#t"
1271
+ @nendo.evalStr( " (values? (values 1)) " ).should == "#f"
1272
+ @nendo.evalStr( " (values 1) " ).should == "1"
1273
+ @nendo.evalStr( " (values? (values 1 2)) " ).should == "#t"
1274
+ @nendo.evalStr( " (values? (values 1 2 3)) " ).should == "#t"
1275
+ @nendo.evalStr( " (values? (values '(a) \"b\" '(\"C\"))) " ).should == "#t"
1276
+ @nendo.evalStr( " (values-values (values)) " ).should == "()"
1277
+ lambda { @nendo.evalStr( " (values-values (values 1)) " ) }.should raise_error(TypeError)
1278
+ @nendo.evalStr( " (values-values (values 1 2)) " ).should == "(1 2)"
1279
+ @nendo.evalStr( " (values-values (values 1 2 3)) " ).should == "(1 2 3)"
1280
+ @nendo.evalStr( " (values-values (values '(a) \"b\" '(\"C\"))) " ).should == '((a) "b" ("C"))'
1281
+ @nendo.evalStr( "" +
1157
1282
  " (call-with-values" +
1158
1283
  " (lambda () (values 4 5)) " +
1159
1284
  " (lambda (a b) b))" ).should == "5"
1160
- @nendo.replStr( "" +
1285
+ @nendo.evalStr( "" +
1161
1286
  " (call-with-values" +
1162
1287
  " (lambda () (values 1 2)) " +
1163
1288
  " cons)" ).should == "(1 . 2)"
1164
- @nendo.replStr( "" +
1289
+ @nendo.evalStr( "" +
1165
1290
  " (call-with-values" +
1166
1291
  " (lambda () (values 10)) " +
1167
1292
  " list)" ).should == "(10)"
1168
- @nendo.replStr( "" +
1293
+ @nendo.evalStr( "" +
1169
1294
  " (call-with-values" +
1170
1295
  " (lambda () (values)) " +
1171
1296
  " list)" ).should == "()"
1172
- @nendo.replStr( " (call-with-values * -) " ).should == "-1"
1173
- @nendo.replStr( " (receive (a) (values) (list a)) " ).should == "()"
1174
- @nendo.replStr( " (receive (a) (values 10) (list a)) " ).should == "(10)"
1175
- @nendo.replStr( " (receive (a b) (values 10 20) (list a b)) " ).should == "(10 20)"
1176
- @nendo.replStr( " (receive (a b c) (values 10 20 30) (list a b c)) " ).should == "(10 20 30)"
1177
- @nendo.replStr( " (receive (a . b) (values 10) (list a b)) " ).should == "(10 ())"
1178
- @nendo.replStr( " (receive (a . b) (values 10 20) (list a b)) " ).should == "(10 (20))"
1179
- @nendo.replStr( " (receive (a . b) (values 10 20 30) (list a b)) " ).should == "(10 (20 30))"
1180
- @nendo.replStr( " (receive all (values) all) " ).should == "()"
1181
- @nendo.replStr( " (receive all (values 10) all) " ).should == "(10)"
1182
- @nendo.replStr( " (receive all (values 10 20) all) " ).should == "(10 20)"
1183
- @nendo.replStr( " (receive all (values 10 20 30) all) " ).should == "(10 20 30)"
1184
- @nendo.replStr( " (receive (a b) (values '(1) '(2)) (list a b)) " ).should == "((1) (2))"
1185
- @nendo.replStr( " (receive (a b) (values '() '(2)) (list a b)) " ).should == "(() (2))"
1186
- @nendo.replStr( " (receive (a b) (values '(1) '()) (list a b)) " ).should == "((1) ())"
1187
- @nendo.replStr( " (receive (a b) (values #t #t) (cons a b)) " ).should == "(#t . #t)"
1188
- @nendo.replStr( " (receive (a b) (values #t #f) (cons a b)) " ).should == "(#t . #f)"
1189
- @nendo.replStr( " (receive (a b) (values nil #t) (cons a b)) " ).should == "(nil . #t)"
1190
- @nendo.replStr( " (receive (a b) (values nil #f) (cons a b)) " ).should == "(nil . #f)"
1191
- @nendo.replStr( " (receive (a b) (values nil nil) (cons a b)) " ).should == "(nil . nil)"
1297
+ @nendo.evalStr( " (call-with-values * -) " ).should == "-1"
1298
+ @nendo.evalStr( " (receive (a) (values) (list a)) " ).should == "()"
1299
+ @nendo.evalStr( " (receive (a) (values 10) (list a)) " ).should == "(10)"
1300
+ @nendo.evalStr( " (receive (a b) (values 10 20) (list a b)) " ).should == "(10 20)"
1301
+ @nendo.evalStr( " (receive (a b c) (values 10 20 30) (list a b c)) " ).should == "(10 20 30)"
1302
+ @nendo.evalStr( " (receive (a . b) (values 10) (list a b)) " ).should == "(10 ())"
1303
+ @nendo.evalStr( " (receive (a . b) (values 10 20) (list a b)) " ).should == "(10 (20))"
1304
+ @nendo.evalStr( " (receive (a . b) (values 10 20 30) (list a b)) " ).should == "(10 (20 30))"
1305
+ @nendo.evalStr( " (receive all (values) all) " ).should == "()"
1306
+ @nendo.evalStr( " (receive all (values 10) all) " ).should == "(10)"
1307
+ @nendo.evalStr( " (receive all (values 10 20) all) " ).should == "(10 20)"
1308
+ @nendo.evalStr( " (receive all (values 10 20 30) all) " ).should == "(10 20 30)"
1309
+ @nendo.evalStr( " (receive (a b) (values '(1) '(2)) (list a b)) " ).should == "((1) (2))"
1310
+ @nendo.evalStr( " (receive (a b) (values '() '(2)) (list a b)) " ).should == "(() (2))"
1311
+ @nendo.evalStr( " (receive (a b) (values '(1) '()) (list a b)) " ).should == "((1) ())"
1312
+ @nendo.evalStr( " (receive (a b) (values #t #t) (cons a b)) " ).should == "(#t . #t)"
1313
+ @nendo.evalStr( " (receive (a b) (values #t #f) (cons a b)) " ).should == "(#t . #f)"
1314
+ @nendo.evalStr( " (receive (a b) (values nil #t) (cons a b)) " ).should == "(nil . #t)"
1315
+ @nendo.evalStr( " (receive (a b) (values nil #f) (cons a b)) " ).should == "(nil . #f)"
1316
+ @nendo.evalStr( " (receive (a b) (values nil nil) (cons a b)) " ).should == "(nil . nil)"
1192
1317
  end
1193
1318
  end
1194
1319
 
@@ -1198,19 +1323,19 @@ describe Nendo, "when toplevel variable was overwritten " do
1198
1323
  @nendo.loadInitFile
1199
1324
  end
1200
1325
  it "should" do
1201
- @nendo.replStr( " (define a 1) a" ).should == "1"
1202
- lambda { @nendo.replStr( " (define (c-func) (+ a b)) (c-func)" ) }.should raise_error( NameError )
1203
- @nendo.replStr( " (define b 2) b" ).should == "2"
1204
- @nendo.replStr( " (c-func) " ).should == "3"
1205
- @nendo.replStr( " (define b 20) " ).should == "20"
1206
- @nendo.replStr( " (c-func) " ).should == "21"
1207
-
1208
- @nendo.replStr( " (define (a-func) 10) (a-func)" ).should == "10"
1209
- lambda { @nendo.replStr( " (define (c-func) (* (a-func) (b-func))) (c-func)" ) }.should raise_error( NameError )
1210
- @nendo.replStr( " (define (b-func) 20) (b-func)" ).should == "20"
1211
- @nendo.replStr( " (c-func) " ).should == "200"
1212
- @nendo.replStr( " (define (b-func) 200) (b-func)" ).should == "200"
1213
- @nendo.replStr( " (c-func) " ).should == "2000"
1326
+ @nendo.evalStr( " (define a 1) a" ).should == "1"
1327
+ lambda { @nendo.evalStr( " (define (c-func) (+ a b)) (c-func)" ) }.should raise_error( NameError )
1328
+ @nendo.evalStr( " (define b 2) b" ).should == "2"
1329
+ @nendo.evalStr( " (c-func) " ).should == "3"
1330
+ @nendo.evalStr( " (define b 20) " ).should == "20"
1331
+ @nendo.evalStr( " (c-func) " ).should == "21"
1332
+
1333
+ @nendo.evalStr( " (define (a-func) 10) (a-func)" ).should == "10"
1334
+ lambda { @nendo.evalStr( " (define (c-func) (* (a-func) (b-func))) (c-func)" ) }.should raise_error( NameError )
1335
+ @nendo.evalStr( " (define (b-func) 20) (b-func)" ).should == "20"
1336
+ @nendo.evalStr( " (c-func) " ).should == "200"
1337
+ @nendo.evalStr( " (define (b-func) 200) (b-func)" ).should == "200"
1338
+ @nendo.evalStr( " (c-func) " ).should == "2000"
1214
1339
  end
1215
1340
  end
1216
1341
 
@@ -1220,18 +1345,18 @@ describe Nendo, "when use quasiquote macro " do
1220
1345
  @nendo.loadInitFile
1221
1346
  end
1222
1347
  it "should" do
1223
- @nendo.replStr( " '(a b c) " ).should == "(a b c)"
1224
- @nendo.replStr( " `(a b c) " ).should == "(a b c)"
1225
- @nendo.replStr( " `(1 2 3) " ).should == "(1 2 3)"
1226
- @nendo.replStr( " (set! a 3) `(1 2 ,a) " ).should == "(1 2 3)"
1227
- @nendo.replStr( " (set! a 3) `(1 2 ,@(list a)) " ).should == "(1 2 3)"
1228
- @nendo.replStr( " (set! a 3) `(1 ,@(list 2 a)) " ).should == "(1 2 3)"
1229
- @nendo.replStr( " (set! a 11) `,a " ).should == "11"
1230
- @nendo.replStr( " (set! a 12) ``,a " ).should == "`,a"
1231
- @nendo.replStr( " `(list ,(+ 1 2) 4) " ).should == "(list 3 4)"
1232
- @nendo.replStr( " (let ((name 'a)) `(list ,name ',name)) " ).should == "(list a 'a)"
1233
- @nendo.replStr( " `(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f) " ).should == "(a `(b ,(+ 1 2) ,(foo 4 d) e) f)"
1234
- @nendo.replStr( " `(( foo ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons))) " ).should == "((foo 7) . cons)"
1348
+ @nendo.evalStr( " '(a b c) " ).should == "(a b c)"
1349
+ @nendo.evalStr( " `(a b c) " ).should == "(a b c)"
1350
+ @nendo.evalStr( " `(1 2 3) " ).should == "(1 2 3)"
1351
+ @nendo.evalStr( " (set! a 3) `(1 2 ,a) " ).should == "(1 2 3)"
1352
+ @nendo.evalStr( " (set! a 3) `(1 2 ,@(list a)) " ).should == "(1 2 3)"
1353
+ @nendo.evalStr( " (set! a 3) `(1 ,@(list 2 a)) " ).should == "(1 2 3)"
1354
+ @nendo.evalStr( " (set! a 11) `,a " ).should == "11"
1355
+ @nendo.evalStr( " (set! a 12) ``,a " ).should == "`,a"
1356
+ @nendo.evalStr( " `(list ,(+ 1 2) 4) " ).should == "(list 3 4)"
1357
+ @nendo.evalStr( " (let ((name 'a)) `(list ,name ',name)) " ).should == "(list a 'a)"
1358
+ @nendo.evalStr( " `(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f) " ).should == "(a `(b ,(+ 1 2) ,(foo 4 d) e) f)"
1359
+ @nendo.evalStr( " `(( foo ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons))) " ).should == "((foo 7) . cons)"
1235
1360
  end
1236
1361
  end
1237
1362
 
@@ -1241,25 +1366,33 @@ describe Nendo, "when use macros made by quasiquote. " do
1241
1366
  @nendo.loadInitFile
1242
1367
  end
1243
1368
  it "should" do
1244
- @nendo.replStr( " (case (length '(1 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"one"'
1245
- @nendo.replStr( " (case (length '(1 2 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"two"'
1246
- @nendo.replStr( " (case (length '(1 2 3 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1247
- @nendo.replStr( " (case (length '(1 2 3 4)) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1248
- @nendo.replStr( " (case 100 ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1249
- @nendo.replStr( " (let* ((a 1) (b (+ a 2))) (cons a b)) " ).should == "(1 . 3)"
1250
- @nendo.replStr( " (let* ((a 10) (b (* a 2))) (cons a b)) " ).should == "(10 . 20)"
1251
- @nendo.replStr( " (let* ((a 10) (b (* a 2)) (c (* b 3))) (list a b c)) " ).should == "(10 20 60)"
1252
- @nendo.replStr( " (begin0 1 2 3) " ).should == "1"
1253
- @nendo.replStr( " (define a 2) (begin0 (set! a (* a 2)) (set! a (* a 2)) (set! a (* a 2)) ) " ).should == "4"
1254
- @nendo.replStr( " (begin0 100) " ).should == "100"
1255
- @nendo.replStr( " (begin0) " ).should == "#f"
1256
- @nendo.replStr( " " +
1369
+ @nendo.evalStr( " (case (length '(1 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"one"'
1370
+ @nendo.evalStr( " (case (length '(1 2 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"two"'
1371
+ @nendo.evalStr( " (case (length '(1 2 3 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1372
+ @nendo.evalStr( " (case (length '(1 2 3 4)) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1373
+ @nendo.evalStr( " (case 100 ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1374
+ @nendo.evalStr( " (let* ((a 1) (b (+ a 2))) (cons a b)) " ).should == "(1 . 3)"
1375
+ @nendo.evalStr( " (let* ((a 10) (b (* a 2))) (cons a b)) " ).should == "(10 . 20)"
1376
+ @nendo.evalStr( " (let* ((a 10) (b (* a 2)) (c (* b 3))) (list a b c)) " ).should == "(10 20 60)"
1377
+ @nendo.evalStr( " (begin0 1 2 3) " ).should == "1"
1378
+ @nendo.evalStr( " (define a 2) (begin0 (set! a (* a 2)) (set! a (* a 2)) (set! a (* a 2)) ) " ).should == "4"
1379
+ @nendo.evalStr( " (begin0 100) " ).should == "100"
1380
+ @nendo.evalStr( " (begin0) " ).should == "#f"
1381
+ @nendo.evalStr( " " +
1257
1382
  "(receive (a b)" +
1258
1383
  " (begin0" +
1259
1384
  " (values 1 2)" +
1260
1385
  " (values 10 20)" +
1261
1386
  " (values 100 200))" +
1262
1387
  " (cons a b))" ).should == "(1 . 2)"
1388
+ @nendo.evalStr( " (macroexpand '(when #t (print \"1\") (print \"2\"))) " ).should == '(if #t (begin (print "1") (print "2")))'
1389
+ @nendo.evalStr( " (macroexpand '(unless #t (print \"1\") (print \"2\"))) " ).should == '(if (not #t) (begin (print "1") (print "2")))'
1390
+ @nendo.evalStr( " (macroexpand '(if-let1 a #t (print \"T\") (print \"F\"))) " ).should == '(let ((a #t)) (if a (print "T") (print "F")))'
1391
+ @nendo.evalStr( " (let1 count 0 (when #t (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "2"
1392
+ @nendo.evalStr( " (let1 count 0 (when #f (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "0"
1393
+ @nendo.evalStr( " (let1 count 0 (unless #t (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "0"
1394
+ @nendo.evalStr( " (let1 count 0 (unless #f (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "2"
1395
+ @nendo.evalStr( " (if-let1 m (rxmatch #/([0-9]+)/ \"abc100abc\") (rxmatch-substring m 1)) " ).should == '"100"'
1263
1396
  end
1264
1397
  end
1265
1398
 
@@ -1269,11 +1402,26 @@ describe Nendo, "when use define and lambda macro " do
1269
1402
  @nendo.loadInitFile
1270
1403
  end
1271
1404
  it "should" do
1272
- @nendo.replStr( " (macroexpand '(define (main argv) (newline) 0)) " ).should == "(define main (lambda (argv) (newline) 0))"
1273
- @nendo.replStr( " (macroexpand '(define (main argv) (define (foo x) x) (+ 10 20) 0 (foo 111))) " ).should == "(define main (lambda (argv) (letrec ((foo (lambda (x) x))) (+ 10 20) (foo 111))))"
1274
- @nendo.replStr( " (define (main argv) (define (foo x) x) (+ 10 20) 0 (foo 111)) (main) " ).should == "111"
1275
- @nendo.replStr( " (define (main argv) (define (foo1 x) (+ 1 x)) (define (foo2 x) (+ 2 x)) (* (foo1 20) (foo2 30))) (main '()) " ).should == "672"
1276
- @nendo.replStr( " (macroexpand '(define (main argv) 0)) " ).should == "(define main (lambda (argv) 0))"
1405
+ @nendo.evalStr( " (macroexpand '(define (main argv) (newline) 0)) " ).should == "(define main (lambda (argv) (newline) 0))"
1406
+ @nendo.evalStr( " (macroexpand '(define (main argv) (define (foo x) x) (+ 10 20) 0 (foo 111))) " ).should == "(define main (lambda (argv) (letrec ((foo (lambda (x) x))) (+ 10 20) 0 (foo 111))))"
1407
+ @nendo.evalStr( " (macroexpand '(define (main argv) (define result '()) (define (foo x) x) (define val 0) (define (bar x) (+ val 10)) )) " ).should == "(define main (lambda (argv) (letrec ((result '()) (foo (lambda (x) x)) (val 0) (bar (lambda (x) (+ val 10)))))))"
1408
+ @nendo.evalStr( " (define (main argv) (define (foo x) x) (+ 10 20) 0 (foo 111)) (main) " ).should == "111"
1409
+ @nendo.evalStr( " (define (main argv) (define (foo1 x) (+ 1 x)) (define (foo2 x) (+ 2 x)) (* (foo1 20) (foo2 30))) (main '()) " ).should == "672"
1410
+ @nendo.evalStr( " (macroexpand '(define (main argv) 0)) " ).should == "(define main (lambda (argv) 0))"
1411
+ end
1412
+ end
1413
+
1414
+ describe Nendo, "when use macro macro " do
1415
+ before do
1416
+ @nendo = Nendo::Core.new()
1417
+ @nendo.loadInitFile
1418
+ end
1419
+ it "should" do
1420
+ @nendo.evalStr( " (define inc!-macro (macro (x) (+ x 1))) #t" ).should == "#t"
1421
+ @nendo.evalStr( " (inc!-macro 10) " ).should == "11"
1422
+ @nendo.evalStr( " (define dec!-macro (macro (x) (define (dec! v) (- v 1)) (dec! x))) #t" ).should == "#t"
1423
+ @nendo.evalStr( " (dec!-macro 10) " ).should == "9"
1424
+ @nendo.evalStr( " (. (dec!-macro 10) class) " ).should == 'Fixnum'
1277
1425
  end
1278
1426
  end
1279
1427
 
@@ -1283,7 +1431,7 @@ describe Nendo, "when use macros expands some syntax. " do
1283
1431
  @nendo.loadInitFile
1284
1432
  end
1285
1433
  it "should" do
1286
- @nendo.replStr( "" +
1434
+ @nendo.evalStr( "" +
1287
1435
  " (let1 total 0" +
1288
1436
  " (let loop ((cnt 10))" +
1289
1437
  " (if (< 0 cnt)" +
@@ -1292,14 +1440,14 @@ describe Nendo, "when use macros expands some syntax. " do
1292
1440
  " (loop (- cnt 1)))))" +
1293
1441
  " total)" +
1294
1442
  "" ).should == "55"
1295
- @nendo.replStr( "" +
1443
+ @nendo.evalStr( "" +
1296
1444
  "(let label ((a 2)" +
1297
1445
  " (b 3))" +
1298
1446
  " (if (<= 9 (+ a b))" +
1299
1447
  " (* a b)" +
1300
1448
  " (label 4 5)))" +
1301
1449
  "" ).should == "20"
1302
- @nendo.replStr( "" +
1450
+ @nendo.evalStr( "" +
1303
1451
  "(macroexpand '(let loop ((x 1)) "+
1304
1452
  " 1"+
1305
1453
  " 2"+
@@ -1313,36 +1461,115 @@ describe Nendo, "when use dot-operator (.) macro " do
1313
1461
  @nendo.loadInitFile
1314
1462
  end
1315
1463
  it "should" do
1316
- @nendo.replStr( " (macroexpand '(. a b)) " ).should == "(a.b)"
1317
- @nendo.replStr( " (macroexpand '(. a b c)) " ).should == "(a.b c)"
1318
- @nendo.replStr( " (macroexpand '(. Kernel open)) " ).should == "(Kernel.open)"
1319
- lambda { @nendo.replStr( " (macroexpand '(. open)) " ) }.should raise_error( ArgumentError )
1320
- lambda { @nendo.replStr( " (macroexpand '(. open \"aaa\")) " ) }.should raise_error( TypeError )
1321
- @nendo.replStr( " (macroexpand '(. a size)) " ).should == "(a.size)"
1322
- @nendo.replStr( " (macroexpand '(. (. a size) to_s)) " ).gsub( /10[0-9][0-9][0-9]/, "10000" ).should == "(let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_10000 (a.size))) (__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_10000.to_s))"
1323
- @nendo.replStr( " (macroexpand '(. (. (. a size) to_s) to_i)) " ).gsub( /10[0-9][0-9][0-9]/, "10000" ).should == "(let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_10000 (let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_10000 (a.size))) (__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_10000.to_s)))) (__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_10000.to_i))"
1324
- lambda { @nendo.replStr( " (macroexpand '(. (. a size))) " ) }.should raise_error( ArgumentError )
1325
- @nendo.replStr( " (set! str \"str\") str.size " ).should == "3"
1326
- @nendo.replStr( " (set! str \"str\") (. str size) " ).should == "3"
1327
- @nendo.replStr( " (set! str \"str\") (+ 1 (. str size)) " ).should == "4"
1328
- @nendo.replStr( " (set! str \"string\") (. (. str size) to_s) " ).should == '"6"'
1329
- @nendo.replStr( " (to-s str.size) " ).should == '"6"'
1330
- @nendo.replStr( " (to-s 'str.size) " ).should == '"str.size"'
1331
- @nendo.replStr( " (require \"date\") " ).should == "#f"
1332
- @nendo.replStr( " (. (Date.new 0) strftime \"%x\") " ).should == '"01/01/00"'
1333
- @nendo.replStr( " (. (Date.new 0) strftime \"%s\") " ).should == '"-62167392000"'
1334
- @nendo.replStr( " (require \"digest/md5\") " ).should == "#f"
1335
- @nendo.replStr( " (Digest::MD5.hexdigest \"abc\") " ).should == '"900150983cd24fb0d6963f7d28e17f72"'
1336
- @nendo.replStr( " (Digest::MD5.hexdigest \"source text\") " ).should == '"20f79a1416626eeacc0bd9a8db87faa2"'
1337
- @nendo.replStr( " (define a 1) (a.is_a? Fixnum) " ).should == "#t"
1338
- @nendo.replStr( " (define a 1) (a.is_a? Float) " ).should == "#f"
1339
- @nendo.replStr( " (define a 1) (a.is_a? String) " ).should == "#f"
1340
- @nendo.replStr( " (define a 1.1) (a.is_a? Fixnum) " ).should == "#f"
1341
- @nendo.replStr( " (define a 1.1) (a.is_a? Float) " ).should == "#t"
1342
- @nendo.replStr( " (define a 1.1) (a.is_a? String) " ).should == "#f"
1343
- @nendo.replStr( " (define a \"s\") (a.is_a? Fixnum) " ).should == "#f"
1344
- @nendo.replStr( " (define a \"s\") (a.is_a? Float) " ).should == "#f"
1345
- @nendo.replStr( " (define a \"s\") (a.is_a? String) " ).should == "#t"
1464
+ @nendo.evalStr( " (macroexpand '(. a b)) " ).should == "(a.b)"
1465
+ @nendo.evalStr( " (macroexpand '(. a b c)) " ).should == "(a.b c)"
1466
+ @nendo.evalStr( " (macroexpand '(. Kernel open)) " ).should == "(Kernel.open)"
1467
+ lambda { @nendo.evalStr( " (macroexpand '(. open)) " ) }.should raise_error( ArgumentError )
1468
+ lambda { @nendo.evalStr( " (macroexpand '(. open \"aaa\")) " ) }.should raise_error( TypeError )
1469
+ @nendo.evalStr( " (macroexpand '(. a size)) " ).should == "(a.size)"
1470
+ @nendo.evalStr( " (macroexpand '(. (. a size) to_s)) " ).gsub( /[12]0[0-9][0-9][0-9]/, "X0000" ).should == "(let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 (a.size))) (__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000.to_s))"
1471
+ @nendo.evalStr( " (macroexpand '(. (. (. a size) to_s) to_i)) " ).gsub( /[12]0[0-9][0-9][0-9]/, "X0000" ).should == "(let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 (let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 (a.size))) (__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000.to_s)))) (__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000.to_i))"
1472
+ lambda { @nendo.evalStr( " (macroexpand '(. (. a size))) " ) }.should raise_error( ArgumentError )
1473
+ @nendo.evalStr( " (set! str \"str\") str.size " ).should == "3"
1474
+ @nendo.evalStr( " (set! str \"str\") (. str size) " ).should == "3"
1475
+ @nendo.evalStr( " (set! str \"str\") (+ 1 (. str size)) " ).should == "4"
1476
+ @nendo.evalStr( " (set! str \"string\") (. (. str size) to_s) " ).should == '"6"'
1477
+ @nendo.evalStr( " (to-s str.size) " ).should == '"6"'
1478
+ @nendo.evalStr( " (to-s 'str.size) " ).should == '"str.size"'
1479
+ @nendo.evalStr( " (require \"date\") " ).should == "#f"
1480
+ @nendo.evalStr( " (. (Date.new 0) strftime \"%x\") " ).should == '"01/01/00"'
1481
+ @nendo.evalStr( " (. (Date.new 0) strftime \"%s\") " ).should == '"-62167392000"'
1482
+ @nendo.evalStr( " (require \"digest/md5\") " ).should == "#f"
1483
+ @nendo.evalStr( " (Digest::MD5.hexdigest \"abc\") " ).should == '"900150983cd24fb0d6963f7d28e17f72"'
1484
+ @nendo.evalStr( " (Digest::MD5.hexdigest \"source text\") " ).should == '"20f79a1416626eeacc0bd9a8db87faa2"'
1485
+ @nendo.evalStr( " (define a 1) (a.is_a? Fixnum) " ).should == "#t"
1486
+ @nendo.evalStr( " (define a 1) (a.is_a? Float) " ).should == "#f"
1487
+ @nendo.evalStr( " (define a 1) (a.is_a? String) " ).should == "#f"
1488
+ @nendo.evalStr( " (define a 1.1) (a.is_a? Fixnum) " ).should == "#f"
1489
+ @nendo.evalStr( " (define a 1.1) (a.is_a? Float) " ).should == "#t"
1490
+ @nendo.evalStr( " (define a 1.1) (a.is_a? String) " ).should == "#f"
1491
+ @nendo.evalStr( " (define a \"s\") (a.is_a? Fixnum) " ).should == "#f"
1492
+ @nendo.evalStr( " (define a \"s\") (a.is_a? Float) " ).should == "#f"
1493
+ @nendo.evalStr( " (define a \"s\") (a.is_a? String) " ).should == "#t"
1494
+ end
1495
+ end
1496
+
1497
+ describe Nendo, "when use dot-operator (.) macro and (&block ...) " do
1498
+ before do
1499
+ @nendo = Nendo::Core.new()
1500
+ @nendo.loadInitFile
1501
+ end
1502
+ it "should" do
1503
+ @nendo.evalStr( " (define arr '#(10 50 40 10000 20 30))" ).should == "#(10 50 40 10000 20 30)"
1504
+ @nendo.evalStr( " (arr.sort)" ).should == "#(10 20 30 40 50 10000)"
1505
+ @nendo.evalStr( " (arr.sort (&block (a b) (if (le? a b) 1 -1))) " ).should == "#(10000 50 40 30 20 10)"
1506
+ @nendo.evalStr( " (arr.sort_by (&block (item) item.to_s)) " ).should == "#(10 10000 20 30 40 50)"
1507
+ end
1508
+ end
1509
+
1510
+ describe Nendo, "when use sort libraries " do
1511
+ before do
1512
+ @nendo = Nendo::Core.new()
1513
+ @nendo.loadInitFile
1514
+ end
1515
+ it "should" do
1516
+ @nendo.evalStr( " (define lst '(1 50 60 30000 4000 200)) " ).should == "(1 50 60 30000 4000 200)"
1517
+ @nendo.evalStr( " (sort lst) " ).should == "(1 50 60 200 4000 30000)"
1518
+ @nendo.evalStr( " (sort '()) " ).should == "()"
1519
+ @nendo.evalStr( " (sort lst (lambda (a b) (- b a))) " ).should == "(30000 4000 200 60 50 1)"
1520
+ @nendo.evalStr( " (sort-by lst (lambda (item) item)) " ).should == "(1 50 60 200 4000 30000)"
1521
+ @nendo.evalStr( " (sort-by '() (lambda (item) item)) " ).should == "()"
1522
+ @nendo.evalStr( " (define lst2 '((1 . \"ddd\") (2 . \"cc\") (3 . \"bbbb\") (4 . \"a\"))) " ).should == '((1 . "ddd") (2 . "cc") (3 . "bbbb") (4 . "a"))'
1523
+ @nendo.evalStr( " (sort lst2 (lambda (a b) (- (car a) (car b)))) " ).should == '((1 . "ddd") (2 . "cc") (3 . "bbbb") (4 . "a"))'
1524
+ @nendo.evalStr( " (sort lst2 (lambda (a b) (if (>= (cdr a) (cdr b)) 1 -1))) " ).should == '((4 . "a") (3 . "bbbb") (2 . "cc") (1 . "ddd"))'
1525
+ @nendo.evalStr( " (sort-by lst2 (lambda (item) (car item))) " ).should == '((1 . "ddd") (2 . "cc") (3 . "bbbb") (4 . "a"))'
1526
+ @nendo.evalStr( " (sort-by lst2 (lambda (item) (cdr item))) " ).should == '((4 . "a") (3 . "bbbb") (2 . "cc") (1 . "ddd"))'
1527
+ @nendo.evalStr( " (sort-by lst2 (lambda (item) (. (cdr item) size))) " ).should == '((4 . "a") (2 . "cc") (1 . "ddd") (3 . "bbbb"))'
1528
+ end
1529
+ end
1530
+
1531
+ describe Nendo, "when use with-open libraries " do
1532
+ before do
1533
+ @nendo = Nendo::Core.new()
1534
+ @nendo.loadInitFile
1535
+ @fn = "/tmp/for-with-open.dat"
1536
+ open( @fn, "w" ) { |f|
1537
+ f.puts( "line1" )
1538
+ f.puts( "line2" )
1539
+ f.puts( "line3" )
1540
+ }
1541
+ end
1542
+ it "should" do
1543
+ @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"line1"'
1544
+ @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"line1"'
1545
+ @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop) (f.readline.chop))) ", @fn )).should == '"line2"'
1546
+ @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.puts \"Wrote from Nendo.\")) \"w\") #t", @fn )).should == "#t"
1547
+ @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"Wrote from Nendo."'
1548
+ lambda { @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) #t) 1 2 ", @fn )) }.should raise_error(RuntimeError)
1549
+ end
1550
+
1551
+ after do
1552
+ File.unlink( @fn )
1553
+ end
1554
+ end
1555
+
1556
+ describe Nendo, "when use (use ...) macro " do
1557
+ before do
1558
+ @nendo = Nendo::Core.new()
1559
+ @nendo.loadInitFile
1560
+ end
1561
+ it "should" do
1562
+ @nendo.evalStr( " (macroexpand '(use abc)) " ).should == '(load-library "abc")'
1563
+ @nendo.evalStr( " (macroexpand '(use a.b)) " ).should == '(load-library "a/b")'
1564
+ @nendo.evalStr( " (macroexpand '(use a.b.c)) " ).should == '(load-library "a/b/c")'
1565
+ @nendo.evalStr( " (macroexpand '(use a.b.c.d.e.f.g)) " ).should == '(load-library "a/b/c/d/e/f/g")'
1566
+ @nendo.evalStr( " (macroexpand '(use srfi-1)) " ).should == '(load-library "srfi-1")'
1567
+ @nendo.evalStr( " (macroexpand '(use text.tree)) " ).should == '(load-library "text/tree")'
1568
+ @nendo.evalStr( " (macroexpand `(use ,(string->symbol (+ \"text\" \".\" \"tree\")))) " ).should == '(load-library "text/tree")'
1569
+ lambda { @nendo.evalStr( " (macroexpand '(use '(a)) " ) }.should raise_error( RuntimeError )
1570
+ lambda { @nendo.evalStr( " (macroexpand '(use \"srfi-1\") " ) }.should raise_error( RuntimeError )
1571
+ lambda { @nendo.evalStr( " (macroexpand '(use 1)) " ) }.should raise_error( RuntimeError )
1572
+ lambda { @nendo.evalStr( " (macroexpand '(use (+ 10 20))) " ) }.should raise_error( RuntimeError )
1346
1573
  end
1347
1574
  end
1348
1575
 
@@ -1352,38 +1579,38 @@ describe Nendo, "when use keyword feature " do
1352
1579
  @nendo.loadInitFile
1353
1580
  end
1354
1581
  it "should" do
1355
- @nendo.replStr( " (keyword? :a) " ).should == "#t"
1356
- @nendo.replStr( ' (keyword? (intern ":a")) ' ).should == "#f"
1357
- @nendo.replStr( ' (symbol? (intern ":a")) ' ).should == "#t"
1358
- @nendo.replStr( " (keyword? ':a) " ).should == "#t"
1359
- @nendo.replStr( " (symbol? ':a) " ).should == "#f"
1360
- @nendo.replStr( " (eq? :a :a) " ).should == "#t"
1361
- @nendo.replStr( " (eqv? :a :a) " ).should == "#t"
1362
- @nendo.replStr( ' (eq? :a (intern ":a")) ' ).should == "#f"
1363
- @nendo.replStr( ' (eqv? :a (intern ":a")) ' ).should == "#f"
1364
- @nendo.replStr( ' (keyword? (make-keyword "a")) ' ).should == "#t"
1365
- @nendo.replStr( " :a " ).should == ":a"
1366
- @nendo.replStr( " ::a " ).should == "::a"
1367
- @nendo.replStr( " :::key " ).should == ":::key"
1368
- @nendo.replStr( ' (make-keyword "a") ' ).should == ":a"
1369
- @nendo.replStr( ' (make-keyword ":a") ' ).should == "::a"
1370
- @nendo.replStr( " (make-keyword 'a) " ).should == ":a"
1371
- @nendo.replStr( " (keyword->string :a) " ).should == '"a"'
1372
- @nendo.replStr( " (keyword->string :abcde) " ).should == '"abcde"'
1373
- lambda { @nendo.replStr( " (keyword->string 'a) " ) }.should raise_error( TypeError )
1374
- @nendo.replStr( " : " ).should == ':'
1375
- @nendo.replStr( " (keyword->string :) " ).should == '""'
1376
- @nendo.replStr( ' (make-keyword "") ' ).should == ":"
1377
- @nendo.replStr( " (get-keyword :y '(:x 1 :y 2 :z 3)) " ).should == "2"
1378
- @nendo.replStr( " (get-keyword 'z '(x 1 y 2 z 3)) " ).should == "3"
1379
- lambda { @nendo.replStr( " (get-keyword 'z '(x 1 y 2 z)) " ) }.should raise_error( RuntimeError )
1380
- lambda { @nendo.replStr( " (get-keyword :t '(:x 1 :y 2 :z 3)) " ) }.should raise_error( RuntimeError )
1381
- @nendo.replStr( " (get-keyword :t '() #f) " ).should == "#f"
1382
- @nendo.replStr( " (get-keyword :t '(:x) #f) " ).should == "#f"
1383
- lambda { @nendo.replStr( " (get-keyword :t '()) " ) }.should raise_error( RuntimeError )
1384
- lambda { @nendo.replStr( " (get-keyword :t '(:x)) " ) }.should raise_error( RuntimeError )
1385
- lambda { @nendo.replStr( " (get-keyword :t 1) " ) }.should raise_error( RuntimeError )
1386
- @nendo.replStr( " (get-keyword :t 1 #f) " ).should == "#f"
1582
+ @nendo.evalStr( " (keyword? :a) " ).should == "#t"
1583
+ @nendo.evalStr( ' (keyword? (intern ":a")) ' ).should == "#f"
1584
+ @nendo.evalStr( ' (symbol? (intern ":a")) ' ).should == "#t"
1585
+ @nendo.evalStr( " (keyword? ':a) " ).should == "#t"
1586
+ @nendo.evalStr( " (symbol? ':a) " ).should == "#f"
1587
+ @nendo.evalStr( " (eq? :a :a) " ).should == "#t"
1588
+ @nendo.evalStr( " (eqv? :a :a) " ).should == "#t"
1589
+ @nendo.evalStr( ' (eq? :a (intern ":a")) ' ).should == "#f"
1590
+ @nendo.evalStr( ' (eqv? :a (intern ":a")) ' ).should == "#f"
1591
+ @nendo.evalStr( ' (keyword? (make-keyword "a")) ' ).should == "#t"
1592
+ @nendo.evalStr( " :a " ).should == ":a"
1593
+ @nendo.evalStr( " ::a " ).should == "::a"
1594
+ @nendo.evalStr( " :::key " ).should == ":::key"
1595
+ @nendo.evalStr( ' (make-keyword "a") ' ).should == ":a"
1596
+ @nendo.evalStr( ' (make-keyword ":a") ' ).should == "::a"
1597
+ @nendo.evalStr( " (make-keyword 'a) " ).should == ":a"
1598
+ @nendo.evalStr( " (keyword->string :a) " ).should == '"a"'
1599
+ @nendo.evalStr( " (keyword->string :abcde) " ).should == '"abcde"'
1600
+ lambda { @nendo.evalStr( " (keyword->string 'a) " ) }.should raise_error( TypeError )
1601
+ @nendo.evalStr( " : " ).should == ':'
1602
+ @nendo.evalStr( " (keyword->string :) " ).should == '""'
1603
+ @nendo.evalStr( ' (make-keyword "") ' ).should == ":"
1604
+ @nendo.evalStr( " (get-keyword :y '(:x 1 :y 2 :z 3)) " ).should == "2"
1605
+ @nendo.evalStr( " (get-keyword 'z '(x 1 y 2 z 3)) " ).should == "3"
1606
+ lambda { @nendo.evalStr( " (get-keyword 'z '(x 1 y 2 z)) " ) }.should raise_error( RuntimeError )
1607
+ lambda { @nendo.evalStr( " (get-keyword :t '(:x 1 :y 2 :z 3)) " ) }.should raise_error( RuntimeError )
1608
+ @nendo.evalStr( " (get-keyword :t '() #f) " ).should == "#f"
1609
+ @nendo.evalStr( " (get-keyword :t '(:x) #f) " ).should == "#f"
1610
+ lambda { @nendo.evalStr( " (get-keyword :t '()) " ) }.should raise_error( RuntimeError )
1611
+ lambda { @nendo.evalStr( " (get-keyword :t '(:x)) " ) }.should raise_error( RuntimeError )
1612
+ lambda { @nendo.evalStr( " (get-keyword :t 1) " ) }.should raise_error( RuntimeError )
1613
+ @nendo.evalStr( " (get-keyword :t 1 #f) " ).should == "#f"
1387
1614
  end
1388
1615
  end
1389
1616
 
@@ -1393,43 +1620,45 @@ describe Nendo, "when use hash-table feature " do
1393
1620
  @nendo.loadInitFile
1394
1621
  end
1395
1622
  it "should" do
1396
- @nendo.replStr( " (define h (make-hash-table)) " ).should == "{}"
1397
- @nendo.replStr( " (hash-table? 1) " ).should == "#f"
1398
- @nendo.replStr( " (hash-table? '(1)) " ).should == "#f"
1399
- @nendo.replStr( " (hash-table? (Array.new)) " ).should == "#f"
1400
- @nendo.replStr( " (hash-table? (Hash.new)) " ).should == "#t"
1401
- @nendo.replStr( " h " ).should == "{}"
1402
- @nendo.replStr( " (hash-table-put! h 'k1 'v1) h" ).should == "{:k1=>:v1}"
1403
- @nendo.replStr( " (hash-table-put! h 'k2 200) h" ).should == "{:k1=>:v1, :k2=>200}"
1404
- @nendo.replStr( " (hash-table-get h 'k1)" ).should == "v1"
1405
- @nendo.replStr( " (hash-table-get h 'k2)" ).should == "200"
1406
- @nendo.replStr( " (hash-table-exist? h 'k1)" ).should == "#t"
1407
- @nendo.replStr( " (hash-table-exist? h 'k2)" ).should == "#t"
1408
- @nendo.replStr( " (hash-table-exist? h 'k3)" ).should == "#f"
1409
- @nendo.replStr( " (hash-table-exist? h \"k1\")" ).should == "#f"
1410
- @nendo.replStr( " (hash-table-num-entries h)" ).should == "2"
1411
- @nendo.replStr( " (hash-table-delete! h 'k1)" ).should == "v1"
1412
- lambda { @nendo.replStr( " (hash-table-get h 'k1)" ) }.should raise_error( RuntimeError )
1413
- @nendo.replStr( " (hash-table-get h 'k1 #f) " ).should == "#f"
1414
- @nendo.replStr( " (hash-table-num-entries h)" ).should == "1"
1415
- @nendo.replStr( " (hash-table-clear! h)" ).should == "{}"
1416
- @nendo.replStr( " (hash-table-num-entries h)" ).should == "0"
1417
- @nendo.replStr( " (set! h (hash-table '(\"a\" \"AAA\") '(\"b\" \"BBB\") '(\"c\" \"CCC\"))) h" ).should == "{\"a\"=>\"AAA\", \"b\"=>\"BBB\", \"c\"=>\"CCC\"}"
1418
- @nendo.replStr( " (set! h (hash-table '(\"a\" . \"AAA\") '(\"b\" . \"BBB\") '(\"c\" . \"CCC\"))) h" ).should == "{\"a\"=>\"AAA\", \"b\"=>\"BBB\", \"c\"=>\"CCC\"}"
1419
- @nendo.replStr( " (hash-table-keys h)" ).should == '("a" "b" "c")'
1420
- @nendo.replStr( " (hash-table-values h)" ).should == '("AAA" "BBB" "CCC")'
1421
- @nendo.replStr( " (hash-table-map h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
1422
- @nendo.replStr( " (hash-table-for-each h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
1423
- @nendo.replStr( " (set! h (hash-table '(a AAA) '(b BBB))) h" ).should == "{:a=>:AAA, :b=>:BBB}"
1424
- @nendo.replStr( " (set! h (hash-table '(a . AAA) '(b BBB))) h" ).should == "{:a=>:AAA, :b=>:BBB}"
1425
- @nendo.replStr( " (set! h (hash-table '(a AAA) '(b . BBB))) h" ).should == "{:a=>:AAA, :b=>:BBB}"
1426
- @nendo.replStr( " (define alist (hash-table->alist h)) alist" ).should == "((a . AAA) (b . BBB))"
1427
- @nendo.replStr( " (define h2 (alist->hash-table alist)) h2" ).should == "{:a=>:AAA, :b=>:BBB}"
1428
- @nendo.replStr( " (set! h (make-hash-table)) " ).should == "{}"
1429
- @nendo.replStr( " (hash-table-push! h 'a :AAA_1) (hash-table->alist h)" ).should == "((a :AAA_1))"
1430
- @nendo.replStr( " (hash-table-push! h 'a :AAA_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1))"
1431
- @nendo.replStr( " (hash-table-push! h 'b :BBB_1) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_1))"
1432
- @nendo.replStr( " (hash-table-push! h 'b :BBB_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_2 :BBB_1))"
1623
+ @nendo.evalStr( " (define h (make-hash-table)) " ).should == "{}"
1624
+ @nendo.evalStr( " (hash-table? 1) " ).should == "#f"
1625
+ @nendo.evalStr( " (hash-table? '(1)) " ).should == "#f"
1626
+ @nendo.evalStr( " (hash-table? (Array.new)) " ).should == "#f"
1627
+ @nendo.evalStr( " (hash-table? (Hash.new)) " ).should == "#t"
1628
+ @nendo.evalStr( " h " ).should == "{}"
1629
+ @nendo.evalStr( " (hash-table-put! h 'k1 'v1) h" ).should == "{:k1=>:v1}"
1630
+ @nendo.evalStr( " (hash-table-put! h 'k2 200) h" ).should == "{:k1=>:v1, :k2=>200}"
1631
+ @nendo.evalStr( " (hash-table-get h 'k1)" ).should == "v1"
1632
+ @nendo.evalStr( " (hash-table-get h 'k2)" ).should == "200"
1633
+ @nendo.evalStr( " (hash-table-exist? h 'k1)" ).should == "#t"
1634
+ @nendo.evalStr( " (hash-table-exist? h 'k2)" ).should == "#t"
1635
+ @nendo.evalStr( " (hash-table-exist? h 'k3)" ).should == "#f"
1636
+ @nendo.evalStr( " (hash-table-exist? h \"k1\")" ).should == "#f"
1637
+ @nendo.evalStr( " (hash-table-num-entries h)" ).should == "2"
1638
+ @nendo.evalStr( " (hash-table-delete! h 'k1)" ).should == "v1"
1639
+ lambda { @nendo.evalStr( " (hash-table-get h 'k1)" ) }.should raise_error( RuntimeError )
1640
+ @nendo.evalStr( " (hash-table-get h 'k1 #f) " ).should == "#f"
1641
+ @nendo.evalStr( " (hash-table-num-entries h)" ).should == "1"
1642
+ @nendo.evalStr( " (hash-table-clear! h)" ).should == "{}"
1643
+ @nendo.evalStr( " (hash-table-num-entries h)" ).should == "0"
1644
+ @nendo.evalStr( " (set! h (hash-table '(\"a\" \"AAA\") '(\"b\" \"BBB\") '(\"c\" \"CCC\" 100))) (hash-table-keys h)" ).should == "(\"a\" \"b\" \"c\")"
1645
+ @nendo.evalStr( " (set! h (hash-table '(\"a\" \"AAA\") '(\"b\" \"BBB\") '(\"c\" \"CCC\" 100))) (hash-table-values h)" ).should == "((\"AAA\") (\"BBB\") (\"CCC\" 100))"
1646
+ @nendo.evalStr( " (set! h (hash-table '(\"a\" . \"AAA\") '(\"b\" . \"BBB\") '(\"c\" . \"CCC\"))) h" ).should == "{\"a\"=>\"AAA\", \"b\"=>\"BBB\", \"c\"=>\"CCC\"}"
1647
+ @nendo.evalStr( " (hash-table-keys h)" ).should == '("a" "b" "c")'
1648
+ @nendo.evalStr( " (hash-table-values h)" ).should == '("AAA" "BBB" "CCC")'
1649
+ @nendo.evalStr( " (hash-table-map h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
1650
+ @nendo.evalStr( " (hash-table-for-each h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
1651
+ @nendo.evalStr( " (set! h (hash-table '(a AAA) '(b BBB))) (hash-table->alist h)" ).should == "((a AAA) (b BBB))"
1652
+ @nendo.evalStr( " (set! h (hash-table '(a . AAA) '(b BBB))) (hash-table->alist h)" ).should == "((a . AAA) (b BBB))"
1653
+ @nendo.evalStr( " (set! h (hash-table '(a AAA) '(b . BBB))) (hash-table->alist h)" ).should == "((a AAA) (b . BBB))"
1654
+ @nendo.evalStr( " (set! h (hash-table '(a . AAA) '(b . BBB))) (hash-table->alist h)" ).should == "((a . AAA) (b . BBB))"
1655
+ @nendo.evalStr( " (define alist (hash-table->alist h)) alist" ).should == "((a . AAA) (b . BBB))"
1656
+ @nendo.evalStr( " (define h2 (alist->hash-table alist)) h2" ).should == "{:a=>:AAA, :b=>:BBB}"
1657
+ @nendo.evalStr( " (set! h (make-hash-table)) " ).should == "{}"
1658
+ @nendo.evalStr( " (hash-table-push! h 'a :AAA_1) (hash-table->alist h)" ).should == "((a :AAA_1))"
1659
+ @nendo.evalStr( " (hash-table-push! h 'a :AAA_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1))"
1660
+ @nendo.evalStr( " (hash-table-push! h 'b :BBB_1) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_1))"
1661
+ @nendo.evalStr( " (hash-table-push! h 'b :BBB_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_2 :BBB_1))"
1433
1662
  end
1434
1663
  end
1435
1664
 
@@ -1439,41 +1668,41 @@ describe Nendo, "when use vector feature " do
1439
1668
  @nendo.loadInitFile
1440
1669
  end
1441
1670
  it "should" do
1442
- @nendo.replStr( " (define v (vector)) v" ).should == "#()"
1443
- @nendo.replStr( " (vector? 1) " ).should == "#f"
1444
- @nendo.replStr( " (vector? (vector)) " ).should == "#t"
1445
- @nendo.replStr( " (vector? (vector 1)) " ).should == "#t"
1446
- @nendo.replStr( " (vector? (vector 1 2)) " ).should == "#t"
1447
- @nendo.replStr( " (vector? '#(1)) " ).should == "#t"
1448
- @nendo.replStr( " (vector? '#(1 2)) " ).should == "#t"
1449
- @nendo.replStr( " (vector? (Array.new)) " ).should == "#t"
1450
- @nendo.replStr( " (vector? (Hash.new)) " ).should == "#f"
1451
- @nendo.replStr( " (vector? 1.1) " ).should == "#f"
1452
- @nendo.replStr( " (vector? \"str\") " ).should == "#f"
1453
- @nendo.replStr( " (define v (make-vector 4))" ).should == "#(nil nil nil nil)"
1454
- @nendo.replStr( " (vector-set! v 0 'v1) v" ).should == "#(v1 nil nil nil)"
1455
- @nendo.replStr( " (vector-set! v 1 '100) v" ).should == "#(v1 100 nil nil)"
1456
- @nendo.replStr( " (vector-set! v 2 '200) v" ).should == "#(v1 100 200 nil)"
1457
- @nendo.replStr( " (vector-set! v 3 '(a b c)) v" ).should == "#(v1 100 200 (a b c))"
1458
- @nendo.replStr( " (vector-length v)" ).should == "4"
1459
- @nendo.replStr( " (vector-ref v 0) " ).should == "v1"
1460
- @nendo.replStr( " (vector-ref v 1) " ).should == "100"
1461
- @nendo.replStr( " (vector-ref v 2) " ).should == "200"
1462
- @nendo.replStr( " (vector-ref v 3) " ).should == "(a b c)"
1463
- lambda { @nendo.replStr( " (vector-ref v -1)" ) }.should raise_error( RuntimeError )
1464
- lambda { @nendo.replStr( " (vector-ref v -2)" ) }.should raise_error( RuntimeError )
1465
- lambda { @nendo.replStr( " (vector-ref v 5)" ) }.should raise_error( RuntimeError )
1466
- lambda { @nendo.replStr( " (vector-ref v 6)" ) }.should raise_error( RuntimeError )
1467
- @nendo.replStr( " (vector-ref v -1 1000)" ).should == "1000"
1468
- @nendo.replStr( " (vector-ref v -2 2000)" ).should == "2000"
1469
- @nendo.replStr( " (vector-ref v 5 3000)" ).should == "3000"
1470
- @nendo.replStr( " (vector-ref v 6 4000)" ).should == "4000"
1471
- @nendo.replStr( " (vector-ref v 7 #f)" ).should == "#f"
1472
- @nendo.replStr( " (define v (make-vector 10)) v" ).should == "#(nil nil nil nil nil nil nil nil nil nil)"
1473
- @nendo.replStr( " (vector->list v)" ).should == "(nil nil nil nil nil nil nil nil nil nil)"
1474
- @nendo.replStr( " (define lst '(a b c (d)))" ).should == "(a b c (d))"
1475
- @nendo.replStr( " (list->vector lst)" ).should == "#(a b c (d))"
1476
- @nendo.replStr( " (list->vector (range 10 1))" ).should == "#(1 2 3 4 5 6 7 8 9 10)"
1671
+ @nendo.evalStr( " (define v (vector)) v" ).should == "#()"
1672
+ @nendo.evalStr( " (vector? 1) " ).should == "#f"
1673
+ @nendo.evalStr( " (vector? (vector)) " ).should == "#t"
1674
+ @nendo.evalStr( " (vector? (vector 1)) " ).should == "#t"
1675
+ @nendo.evalStr( " (vector? (vector 1 2)) " ).should == "#t"
1676
+ @nendo.evalStr( " (vector? '#(1)) " ).should == "#t"
1677
+ @nendo.evalStr( " (vector? '#(1 2)) " ).should == "#t"
1678
+ @nendo.evalStr( " (vector? (Array.new)) " ).should == "#t"
1679
+ @nendo.evalStr( " (vector? (Hash.new)) " ).should == "#f"
1680
+ @nendo.evalStr( " (vector? 1.1) " ).should == "#f"
1681
+ @nendo.evalStr( " (vector? \"str\") " ).should == "#f"
1682
+ @nendo.evalStr( " (define v (make-vector 4))" ).should == "#(nil nil nil nil)"
1683
+ @nendo.evalStr( " (vector-set! v 0 'v1) v" ).should == "#(v1 nil nil nil)"
1684
+ @nendo.evalStr( " (vector-set! v 1 '100) v" ).should == "#(v1 100 nil nil)"
1685
+ @nendo.evalStr( " (vector-set! v 2 '200) v" ).should == "#(v1 100 200 nil)"
1686
+ @nendo.evalStr( " (vector-set! v 3 '(a b c)) v" ).should == "#(v1 100 200 (a b c))"
1687
+ @nendo.evalStr( " (vector-length v)" ).should == "4"
1688
+ @nendo.evalStr( " (vector-ref v 0) " ).should == "v1"
1689
+ @nendo.evalStr( " (vector-ref v 1) " ).should == "100"
1690
+ @nendo.evalStr( " (vector-ref v 2) " ).should == "200"
1691
+ @nendo.evalStr( " (vector-ref v 3) " ).should == "(a b c)"
1692
+ lambda { @nendo.evalStr( " (vector-ref v -1)" ) }.should raise_error( RuntimeError )
1693
+ lambda { @nendo.evalStr( " (vector-ref v -2)" ) }.should raise_error( RuntimeError )
1694
+ lambda { @nendo.evalStr( " (vector-ref v 5)" ) }.should raise_error( RuntimeError )
1695
+ lambda { @nendo.evalStr( " (vector-ref v 6)" ) }.should raise_error( RuntimeError )
1696
+ @nendo.evalStr( " (vector-ref v -1 1000)" ).should == "1000"
1697
+ @nendo.evalStr( " (vector-ref v -2 2000)" ).should == "2000"
1698
+ @nendo.evalStr( " (vector-ref v 5 3000)" ).should == "3000"
1699
+ @nendo.evalStr( " (vector-ref v 6 4000)" ).should == "4000"
1700
+ @nendo.evalStr( " (vector-ref v 7 #f)" ).should == "#f"
1701
+ @nendo.evalStr( " (define v (make-vector 10)) v" ).should == "#(nil nil nil nil nil nil nil nil nil nil)"
1702
+ @nendo.evalStr( " (vector->list v)" ).should == "(nil nil nil nil nil nil nil nil nil nil)"
1703
+ @nendo.evalStr( " (define lst '(a b c (d)))" ).should == "(a b c (d))"
1704
+ @nendo.evalStr( " (list->vector lst)" ).should == "#(a b c (d))"
1705
+ @nendo.evalStr( " (list->vector (range 10 1))" ).should == "#(1 2 3 4 5 6 7 8 9 10)"
1477
1706
  end
1478
1707
  end
1479
1708
 
@@ -1484,17 +1713,17 @@ describe Nendo, "tail call optimization " do
1484
1713
  @nendo.loadInitFile # to self optimizing. The init.nnd file will be loaded twice, so `filter' can be optimized on second loading phase.
1485
1714
  end
1486
1715
  it "should" do
1487
- @nendo.replStr( " (setup-tailcall-mark '(print \"abc\")) " ).should == "(%tailcall (print \"abc\"))"
1488
- @nendo.replStr( " (setup-tailcall-mark '(begin (print \"abc\") 1 2 3)) " ).should == "(begin (print \"abc\") 1 2 3)"
1489
- @nendo.replStr( " (setup-tailcall-mark '(begin 1 2 (print \"abc\") 3)) " ).should == "(begin 1 2 (print \"abc\") 3)"
1490
- @nendo.replStr( " (setup-tailcall-mark '(begin 1 2 3 (print \"abc\"))) " ).should == "(begin 1 2 3 (%tailcall (print \"abc\")))"
1491
- @nendo.replStr( "" +
1716
+ @nendo.evalStr( " (setup-tailcall-mark '(print \"abc\")) " ).should == "(%tailcall (print \"abc\"))"
1717
+ @nendo.evalStr( " (setup-tailcall-mark '(begin (print \"abc\") 1 2 3)) " ).should == "(begin (print \"abc\") 1 2 3)"
1718
+ @nendo.evalStr( " (setup-tailcall-mark '(begin 1 2 (print \"abc\") 3)) " ).should == "(begin 1 2 (print \"abc\") 3)"
1719
+ @nendo.evalStr( " (setup-tailcall-mark '(begin 1 2 3 (print \"abc\"))) " ).should == "(begin 1 2 3 (%tailcall (print \"abc\")))"
1720
+ @nendo.evalStr( "" +
1492
1721
  "(setup-tailcall-mark"+
1493
1722
  " '(lambda '(x)"+
1494
1723
  " 1"+
1495
1724
  " 2"+
1496
1725
  " (print \"abc\")))" ).should == "(lambda '(x) 1 2 (%tailcall (print \"abc\")))"
1497
- @nendo.replStr( "" +
1726
+ @nendo.evalStr( "" +
1498
1727
  "(setup-tailcall-mark"+
1499
1728
  " '(lambda (x)"+
1500
1729
  " 1"+
@@ -1502,31 +1731,31 @@ describe Nendo, "tail call optimization " do
1502
1731
  " (if #t"+
1503
1732
  " (begin 1 2 (print \"abc\"))"+
1504
1733
  " (begin 1 2 (print \"ABC\")))))" ).should == "(lambda (x) 1 2 (if #t (begin 1 2 (%tailcall (print \"abc\"))) (begin 1 2 (%tailcall (print \"ABC\")))))"
1505
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1734
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1506
1735
  " '(define (foo) (foo))"+
1507
1736
  " ))" ).should == "(define foo (lambda () (%tailcall (foo))))"
1508
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1737
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1509
1738
  " '(values? (make-values '()))"+
1510
1739
  " ))" ).should == "(%tailcall (values? (make-values '())))"
1511
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1740
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1512
1741
  " '(cond (false 1) (false 2))"+
1513
1742
  " ))" ).should == "(if #f (begin 1) (if #f (begin 2) ()))"
1514
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1743
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1515
1744
  " '(cond (false 1) (false 2) (else 3))"+
1516
1745
  " ))" ).should == "(if #f (begin 1) (if #f (begin 2) (if #t (begin 3) ())))"
1517
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1746
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1518
1747
  " '(and (foo 1) (bar 2))"+
1519
1748
  " ))" ).should == "(if (not (eq? #f (foo 1))) (%tailcall (bar 2)) #f)"
1520
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1749
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1521
1750
  " '(or (foo 1) (bar 2))"+
1522
- " ))" ).gsub( /20[0-9][0-9][0-9]/, "20000" ).should == "(let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_20000 (foo 1))) (if __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_20000 __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_20000 (let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_20000 (bar 2))) (if __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_20000 __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_20000 #f))))"
1523
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1751
+ " ))" ).gsub( /[24]0[0-9][0-9][0-9]/, "X0000" ).should == "(let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 (foo 1))) (if __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 (let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 (bar 2))) (if __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 __gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 #f))))"
1752
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1524
1753
  " '(let loop ((x 1)) 1 2 (loop 100))"+
1525
1754
  " ))" ).should == "(letrec ((loop (lambda (x) 1 2 (%tailcall (loop 100))))) (%tailcall (loop 1)))"
1526
- @nendo.replStr( "(setup-tailcall-mark (macroexpand "+
1755
+ @nendo.evalStr( "(setup-tailcall-mark (macroexpand "+
1527
1756
  " '(let1 aaa 111 aaa)"+
1528
1757
  " ))" ).should == "(let ((aaa 111)) aaa)"
1529
- @nendo.replStr( "" +
1758
+ @nendo.evalStr( "" +
1530
1759
  "(setup-tailcall-mark"+
1531
1760
  " '(letrec ((func1 "+
1532
1761
  " (lambda (x)"+
@@ -1537,13 +1766,15 @@ describe Nendo, "tail call optimization " do
1537
1766
  " 2"+
1538
1767
  " (func1))))"+
1539
1768
  " (func1 100)))" ).should == "(letrec ((func1 (lambda (x) 1 (%tailcall (func2)))) (func2 (lambda (x) 2 (%tailcall (func1))))) (%tailcall (func1 100)))"
1540
- @nendo.replStr( "(set-optimize-level 0) " ).should == "0"
1541
- lambda { @nendo.replStr( "(filter (lambda (x) (< x 10)) (range 10000)) " ) }.should raise_error(SystemStackError)
1542
- @nendo.replStr( "(set-optimize-level 1) " ).should == "1"
1543
- @nendo.replStr( "(filter (lambda (x) (< x 10)) (range 10000)) " ).should == "(0 1 2 3 4 5 6 7 8 9)"
1544
- @nendo.replStr( "(define str (if #t (car '(\"a\")) (car '(\"b\")))) (sprintf \"A%sZ\" str) " ).should == '"AaZ"'
1545
- @nendo.replStr( "(letrec ((str (if #t (+ \"a\" \"A\") '()))) str.class) " ).should == 'String'
1546
- @nendo.replStr( "(letrec ((str (if #t (+ \"a\" \"A\") '()))) (+ str \"...\")) " ).should == '"aA..."'
1769
+ @nendo.evalStr( "(set-optimize-level 0) " ).should == "0"
1770
+ lambda { @nendo.evalStr( "(filter (lambda (x) (< x 10)) (range 10000)) " ) }.should raise_error(SystemStackError)
1771
+ @nendo.evalStr( "(set-optimize-level 1) " ).should == "1"
1772
+ @nendo.evalStr( "(apply + (map (lambda (x) (* x 2)) (range 10000))) " ).should == "99990000"
1773
+ @nendo.evalStr( "(filter (lambda (x) (< x 10)) (range 1000)) " ).should == "(0 1 2 3 4 5 6 7 8 9)"
1774
+ @nendo.evalStr( "(filter-map (lambda (x) (when (< x 10) (- x))) (range 1000)) " ).should == "(0 -1 -2 -3 -4 -5 -6 -7 -8 -9)"
1775
+ @nendo.evalStr( "(define str (if #t (car '(\"a\")) (car '(\"b\")))) (sprintf \"A%sZ\" str) " ).should == '"AaZ"'
1776
+ @nendo.evalStr( "(letrec ((str (if #t (+ \"a\" \"A\") '()))) str.class) " ).should == 'String'
1777
+ @nendo.evalStr( "(letrec ((str (if #t (+ \"a\" \"A\") '()))) (+ str \"...\")) " ).should == '"aA..."'
1547
1778
  end
1548
1779
  end
1549
1780
 
@@ -1554,13 +1785,82 @@ describe Nendo, "optional argument parser " do
1554
1785
  @nendo.loadInitFile
1555
1786
  end
1556
1787
  it "should" do
1557
- @nendo.replStr( " (get-optional '() 100) " ).should == "100"
1558
- @nendo.replStr( " (get-optional '(1) 100) " ).should == "1"
1559
- @nendo.replStr( " (get-optional '(2) 100) " ).should == "2"
1560
- @nendo.replStr( " (get-optional '(3 4) 100) " ).should == "3"
1561
- @nendo.replStr( " (get-optional '() #t) " ).should == "#t"
1562
- @nendo.replStr( " (get-optional '() #f) " ).should == "#f"
1788
+ @nendo.evalStr( " (get-optional '() 100) " ).should == "100"
1789
+ @nendo.evalStr( " (get-optional '(1) 100) " ).should == "1"
1790
+ @nendo.evalStr( " (get-optional '(2) 100) " ).should == "2"
1791
+ @nendo.evalStr( " (get-optional '(3 4) 100) " ).should == "3"
1792
+ @nendo.evalStr( " (get-optional '() #t) " ).should == "#t"
1793
+ @nendo.evalStr( " (get-optional '() #f) " ).should == "#f"
1794
+ end
1795
+ end
1796
+
1797
+
1798
+ describe Nendo, "nendo.test library " do
1799
+ before do
1800
+ @nendo = Nendo::Core.new()
1801
+ @nendo.loadInitFile
1802
+ end
1803
+ it "should" do
1804
+ @nendo.evalStr( " (when (load-library \"nendo/test\") #t) " ).should == "#t"
1805
+ @nendo.evalStr( " (when (File.exist? *test-record-file*) (File.unlink *test-record-file*)) #t" ).should == "#t"
1806
+ @nendo.evalStr( " (test-output-file (.open \"/dev/null\" \"w\")) #t" ).should == "#t"
1807
+ @nendo.evalStr( " (test-start \"EMPTY\") " ).should == '"EMPTY"'
1808
+ @nendo.evalStr( " (test-section \"EMPTY-SECTION\") " ).should == '"EMPTY-SECTION"'
1809
+ @nendo.evalStr( " (test-end) " ).should == '0'
1810
+ @nendo.evalStr( " *test-counts* " ).should == '#(0 0 0 0)'
1811
+
1812
+ @nendo.evalStr( " (test-start \"SUCCESS\") " ).should == '"SUCCESS"'
1813
+ @nendo.evalStr( " (test-section \"SUCCESS-SECTION\") " ).should == '"SUCCESS-SECTION"'
1814
+ @nendo.evalStr( " (test \"test 1\" 1 (lambda () 1)) *test-counts*" ).should == '#(1 1 0 0)'
1815
+ @nendo.evalStr( " (test* \"test 2\" 1 1 eq?) *test-counts*" ).should == '#(2 2 0 0)'
1816
+ @nendo.evalStr( " (test* \"test 3\" (+ 2 2) (* 2 2) eqv?) *test-counts*" ).should == '#(3 3 0 0)'
1817
+ @nendo.evalStr( " (test* \"test 4\" \"abc\" (+ \"a\" \"b\" \"c\")) *test-counts*" ).should == '#(4 4 0 0)'
1818
+ @nendo.evalStr( " (test* \"test 5\" '(1 . 2) (cons 1 2)) *test-counts*" ).should == '#(5 5 0 0)'
1819
+ @nendo.evalStr( " (test-end) " ).should == '0'
1820
+ @nendo.evalStr( " *test-counts* " ).should == '#(5 5 0 0)'
1821
+
1822
+ @nendo.evalStr( " (test-start \"FAIL\") " ).should == '"FAIL"'
1823
+ @nendo.evalStr( " (test-section \"FAIL-SECTION\") " ).should == '"FAIL-SECTION"'
1824
+ @nendo.evalStr( " (test \"test 6\" 1 (lambda () 2)) *test-counts*" ).should == '#(6 5 1 0)'
1825
+ @nendo.evalStr( " (test* \"test 7\" 1 2 eqv?) *test-counts*" ).should == '#(7 5 2 0)'
1826
+ @nendo.evalStr( " (test* \"test 8\" '(1) '(1) eq?) *test-counts*" ).should == '#(8 5 3 0)'
1827
+ @nendo.evalStr( " (test* \"test 9\" \"ABC\" (+ \"a\" \"b\" \"c\")) *test-counts*" ).should == '#(9 5 4 0)'
1828
+ @nendo.evalStr( " (test* \"test 10\" '(1 . 2) (cons 10 20)) *test-counts*" ).should == '#(10 5 5 0)'
1829
+ @nendo.evalStr( " (test-end) " ).should == '5'
1830
+ @nendo.evalStr( " *test-counts* " ).should == '#(10 5 5 0)'
1831
+
1832
+ @nendo.evalStr( " (define data #f) data" ).should == "#f"
1833
+ @nendo.evalStr( " (with-open *test-record-file* (lambda (in) (set! data (in.readline.chomp)))) data " ).should ==
1834
+ '"Total: 10 tests, 5 passed, 5 failed, 0 aborted."'
1563
1835
  end
1564
1836
  end
1565
1837
 
1566
1838
 
1839
+ describe Nendo, "when use export-to-ruby macro " do
1840
+ before do
1841
+ @nendo = Nendo::Core.new()
1842
+ @nendo.loadInitFile
1843
+ end
1844
+ it "should" do
1845
+ @nendo.evalStr( " (define (nendo_function0 ) 0) #t" ).should == "#t"
1846
+ @nendo.evalStr( " (define (nendo_function1 x) (+ x 1)) #t" ).should == "#t"
1847
+ @nendo.evalStr( " (define (nendo_function2 x y) (* x y)) #t" ).should == "#t"
1848
+ @nendo.evalStr( " (define (nendo_function7 a b c d e f g) (to-arr (list a b c d e f g))) #t" ).should == "#t"
1849
+ @nendo.evalStr( " (export-to-ruby nendo_function0) " ).should == "#t"
1850
+ @nendo.evalStr( " (export-to-ruby nendo_function1) " ).should == "#t"
1851
+ @nendo.evalStr( " (export-to-ruby nendo_function2) " ).should == "#t"
1852
+ @nendo.evalStr( " (export-to-ruby nendo_function7) " ).should == "#t"
1853
+ @nendo.evalStr( " (macroexpand '(export-to-ruby nendo_function1)) " ).should == '(%export-to-ruby "nendo_function1" nendo_function1)'
1854
+ @nendo.evalStr( " (macroexpand '(export-to-ruby nendo_function7)) " ).should == '(%export-to-ruby "nendo_function7" nendo_function7)'
1855
+ @nendo.evalStr( " (define (a-func0) 0) #t" ).should == "#t"
1856
+ lambda { @nendo.evalStr( " (export-to-ruby a-func0) " ) }.should raise_error(ArgumentError)
1857
+ @nendo.evalStr( " (define (clone) 0) #t" ).should == "#t"
1858
+ lambda { @nendo.evalStr( " (export-to-ruby clone) " ) }.should raise_error(RuntimeError)
1859
+ @nendo.evalStr( " (define variable_a 0) #t" ).should == "#t"
1860
+ lambda { @nendo.evalStr( " (export-to-ruby variable_a) " ) }.should raise_error(ArgumentError)
1861
+ @nendo.nendo_function0.should == 0
1862
+ @nendo.nendo_function1( 10 ).should == 11
1863
+ @nendo.nendo_function2( 8, 9 ).should == 72
1864
+ @nendo.nendo_function7( 7,6,5,4,3,2,1 ).should === [ 7,6,5,4,3,2,1 ]
1865
+ end
1866
+ end