nendo 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/test/nendo_spec.rb CHANGED
@@ -306,7 +306,7 @@ describe Nendo, "when reference global-variables." do
306
306
  it "should" do
307
307
  @nendo.evalStr( " (pair? *load-path*) " ).should == "#t"
308
308
  @nendo.evalStr( " (string? (car *load-path*)) " ).should == "#t"
309
- @nendo.evalStr( " (to-arr *load-path*) " ).should include( "./spec")
309
+ # @nendo.evalStr( " (to-arr *load-path*) " ).should include( "./spec")
310
310
  @nendo.evalStr( " (to-arr *load-path*) " ).should include( "./lib")
311
311
  @nendo.evalStr( " (string? (*FILE*)) " ).should == "#t"
312
312
  @nendo.evalStr( " (number? (*LINE*)) " ).should == "#t"
@@ -536,2160 +536,3 @@ describe Nendo, "when call evalStr() with `modulo' function" do
536
536
  end
537
537
  end
538
538
 
539
- describe Nendo, "when use quote and syntax-quote " do
540
- before do
541
- @nendo = Nendo::Core.new()
542
- end
543
- it "should" do
544
- @nendo.evalStr( " '() " ).should == "()"
545
- @nendo.evalStr( " '1 " ).should == "1"
546
- @nendo.evalStr( " '\"str\" " ).should == '"str"'
547
- @nendo.evalStr( " '(1 . 2) " ).should == "(1 . 2)"
548
- @nendo.evalStr( " (quote ())" ).should == "()"
549
- @nendo.evalStr( " (quote 1)" ).should == "1"
550
- @nendo.evalStr( " (quote \"str\") " ).should == '"str"'
551
- @nendo.evalStr( " (quote (1 . 2)) " ).should == "(1 . 2)"
552
- @nendo.evalStr( " (syntax-quote ())" ).should == "()"
553
- @nendo.evalStr( " (syntax-quote 1)" ).should == "1"
554
- @nendo.evalStr( ' (syntax-quote "str") ' ).should == '"str"'
555
- @nendo.evalStr( " (syntax-quote (1 . 2)) " ).should == "(1 . 2)"
556
- @nendo.evalStr( " (quote quote) " ).should == "quote"
557
- @nendo.evalStr( " 'quote " ).should == "quote"
558
- @nendo.evalStr( " ''1 " ).should == "(quote 1)"
559
- @nendo.evalStr( " (quote syntax-quote) " ).should == "quote"
560
- @nendo.evalStr( " (syntax-quote '1) " ).should == "(quote 1)"
561
- @nendo.evalStr( " (syntax-quote (quote 1)) " ).should == "(quote 1)"
562
- @nendo.evalStr( " (quote (syntax-quote 1)) " ).should == "(quote 1)"
563
- end
564
- end
565
-
566
- describe Nendo, "when read various list expressions" do
567
- before do
568
- @nendo = Nendo::Core.new()
569
- end
570
- it "should" do
571
- @nendo.evalStr( " '() " ).should == "()"
572
- @nendo.evalStr( " '[] " ).should == "()"
573
- @nendo.evalStr( " '(1 . 1) " ).should == "(1 . 1)"
574
- @nendo.evalStr( " '[1 . 1) " ).should == "(1 . 1)"
575
- @nendo.evalStr( " '(1 . 1] " ).should == "(1 . 1)"
576
- @nendo.evalStr( " '(1 1 . 1) " ).should == "(1 1 . 1)"
577
- @nendo.evalStr( " '(1 2 . 3) " ).should == "(1 2 . 3)"
578
- @nendo.evalStr( " '(1 2 3) " ).should == "(1 2 3)"
579
- @nendo.evalStr( " '(1.1 2.2 3.3) " ).should == "(1.1 2.2 3.3)"
580
- @nendo.evalStr( " '(a bb ccc dddd) " ).should == "(a bb ccc dddd)"
581
- @nendo.evalStr( " '(a (b) ((c)) (((d)))) " ).should == "(a (b) ((c)) (((d))))"
582
- @nendo.evalStr( " '[a (b) ((c)) (((d)))] " ).should == "(a (b) ((c)) (((d))))"
583
- @nendo.evalStr( " '(a [b] ([c]) (([d]))) " ).should == "(a (b) ((c)) (((d))))"
584
- @nendo.evalStr( " '[a [b] [[c]] [[[d]]]] " ).should == "(a (b) ((c)) (((d))))"
585
- @nendo.evalStr( " '('a)" ).should == "((quote a))"
586
- @nendo.evalStr( " '(''a)" ).should == "((quote (quote a)))"
587
- @nendo.evalStr( " '('a 'b 'c)" ).should == "((quote a) (quote b) (quote c))"
588
- @nendo.evalStr( ' \'("str") ' ).should == '("str")'
589
- @nendo.evalStr( ' \'("str" . 1) ' ).should == '("str" . 1)'
590
- @nendo.evalStr( ' \'(1 . "str") ' ).should == '(1 . "str")'
591
- @nendo.evalStr( ' \'(1 2 . "str") ' ).should == '(1 2 . "str")'
592
- @nendo.evalStr( " '((a)(b)(c)) " ).should == "((a) (b) (c))"
593
- @nendo.evalStr( " 'a " ).should == "a"
594
- @nendo.evalStr( " 'symbol " ).should == "symbol"
595
- @nendo.evalStr( " 'SYMBOL " ).should == "SYMBOL"
596
- @nendo.evalStr( " 'SyMbOl " ).should == "SyMbOl"
597
- @nendo.evalStr( " ''a " ).should == "(quote a)"
598
- @nendo.evalStr( " '1 " ).should == "1"
599
- @nendo.evalStr( " ''1 " ).should == "(quote 1)"
600
- @nendo.evalStr( " '''1 " ).should == "(quote (quote 1))"
601
- @nendo.evalStr( " '1.1 " ).should == "1.1"
602
- @nendo.evalStr( " ''1.1 " ).should == "(quote 1.1)"
603
- @nendo.evalStr( " '''1.1 " ).should == "(quote (quote 1.1))"
604
- @nendo.evalStr( " '() " ).should == "()"
605
- @nendo.evalStr( " '(()) " ).should == "(())"
606
- @nendo.evalStr( " '((())) " ).should == "((()))"
607
- @nendo.evalStr( " '(((()))) " ).should == "(((())))"
608
- @nendo.evalStr( " '(() . ()) " ).should == "(())"
609
- @nendo.evalStr( " '(a . ()) " ).should == "(a)"
610
- @nendo.evalStr( " '(a . #t) " ).should == "(a . #t)"
611
- @nendo.evalStr( " '(a . #f) " ).should == "(a . #f)"
612
- @nendo.evalStr( " '(a . nil) " ).should == "(a . nil)"
613
- @nendo.evalStr( " '(a b c d e . ()) " ).should == "(a b c d e)"
614
- @nendo.evalStr( " '(#t #t #f #f nil nil '() '()) " ).should == "(#t #t #f #f nil nil (quote ()) (quote ()))"
615
- end
616
- end
617
-
618
-
619
-
620
-
621
- class TestClassForBlockArgument
622
- def arg1
623
- yield 100
624
- end
625
- def arg2
626
- yield 100,200
627
- end
628
- def arg5
629
- yield 10,20,30,40,50
630
- end
631
-
632
- def arg1_plus_1( arg1 )
633
- yield arg1, 200
634
- end
635
-
636
- end
637
-
638
- describe Nendo, "when use &block(Ruby's block) " do
639
- before do
640
- @nendo = Nendo::Core.new()
641
- end
642
-
643
- it "should" do
644
- @nendo.evalStr( " (define testclass (TestClassForBlockArgument.new)) testclass.class" ).should == "TestClassForBlockArgument"
645
- @nendo.evalStr( " (testclass.arg1 (&block (a) (list a))) " ).should == "(100)"
646
- @nendo.evalStr( " (testclass.arg2 (&block (a b) (cons a b))) " ).should == "(100 . 200)"
647
- @nendo.evalStr( " (testclass.arg5 (&block (a b c d e) (list a b c d e))) " ).should == "(10 20 30 40 50)"
648
- @nendo.evalStr( " (testclass.arg5 (&block (a b c d e) (to-arr (list a b c d e)))) " ).should == "#(10 20 30 40 50)"
649
- end
650
- end
651
-
652
- describe Nendo, "when call variable length functions" do
653
- before do
654
- @nendo = Nendo::Core.new()
655
- @nendo.loadInitFile
656
- end
657
- it "should" do
658
- # fixed length
659
- @nendo.evalStr( <<EOS
660
- (define (arg0) 0)
661
- (define (arg1 a) a)
662
- (define (arg2 a b) b)
663
- (define (arg3 a b c) c)
664
- (define (arg4 a b c d) d)
665
- (list
666
- (arg0)
667
- (arg1 1)
668
- (arg2 1 2)
669
- (arg3 1 2 3)
670
- (arg4 1 2 3 4))
671
- EOS
672
- ).should == "(0 1 2 3 4)"
673
-
674
- @nendo.evalStr( <<EOS
675
- (define (func-var-arg . arg) arg)
676
- (list
677
- (func-var-arg)
678
- (func-var-arg 1)
679
- (func-var-arg 1 2)
680
- (func-var-arg 1 2 3)
681
- (func-var-arg 1 2 3 4))
682
- EOS
683
- ).should == "(() (1) (1 2) (1 2 3) (1 2 3 4))"
684
-
685
- @nendo.evalStr( <<EOS
686
- (define (func-var-arg first . rest) rest)
687
- (list
688
- (func-var-arg 0)
689
- (func-var-arg 0 1)
690
- (func-var-arg 0 1 2)
691
- (func-var-arg 0 1 2 3)
692
- (func-var-arg 0 1 2 3 4))
693
- EOS
694
- ).should == "(() (1) (1 2) (1 2 3) (1 2 3 4))"
695
-
696
- @nendo.evalStr( <<EOS
697
- (define (func-var-arg first second . rest) (cons second rest))
698
- (list
699
- (func-var-arg "f" "s")
700
- (func-var-arg "f" "s" 1)
701
- (func-var-arg "f" "s" 1 2)
702
- (func-var-arg "f" "s" 1 2 3)
703
- (func-var-arg "f" "s" 1 2 3 4))
704
- EOS
705
- ).should == '(("s") ("s" 1) ("s" 1 2) ("s" 1 2 3) ("s" 1 2 3 4))'
706
-
707
- # Ruby method with block
708
- @nendo.evalStr( <<EOS
709
- (define testclass (TestClassForBlockArgument.new)) testclass.class
710
- (list
711
- (testclass.arg1 (&block (a) (list a)))
712
- (testclass.arg2 (&block (a b) (cons a b)))
713
- (testclass.arg1_plus_1 "a" (&block (a b) (list a b)))
714
- )
715
- EOS
716
- ).should == '((100) (100 . 200) ("a" 200))'
717
-
718
-
719
- # Ruby method with block
720
- @nendo.evalStr( <<EOS
721
- (define (read-first-line fobj) (fobj.readline.chomp))
722
- (let1 filename "./VERSION.yml"
723
- (list
724
- (with-open filename read-first-line "r")
725
- (with-open filename read-first-line)))
726
- EOS
727
- ).should == '("---" "---")'
728
- end
729
- end
730
-
731
-
732
- describe Nendo, "when read various vector expressions" do
733
- before do
734
- @nendo = Nendo::Core.new()
735
- @nendo.setDisplayErrors( false )
736
- end
737
- it "should" do
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))))"
755
- end
756
- end
757
-
758
- describe Nendo, "when call evalStr() with built-in functions" do
759
- before do
760
- @nendo = Nendo::Core.new()
761
- @nendo.setDisplayErrors( false )
762
- end
763
- it "should" do
764
- @nendo.evalStr( " (car '(1 2 3 4)) " ).should == "1"
765
- @nendo.evalStr( " (cdr '(1 2 3 4)) " ).should == "(2 3 4)"
766
- @nendo.evalStr( " (null? '()) " ).should == "#t"
767
- @nendo.evalStr( " (null? '(1)) " ).should == "#f"
768
- @nendo.evalStr( " (null? false) " ).should == "#f"
769
- @nendo.evalStr( " (null? nil) " ).should == "#f"
770
- @nendo.evalStr( " (null? true) " ).should == "#f"
771
- @nendo.evalStr( " (cons 1 2) " ).should == "(1 . 2)"
772
- @nendo.evalStr( " (cons 1 '(2 3)) " ).should == "(1 2 3)"
773
- @nendo.evalStr( " (cons '(1 2) '(3 4)) " ).should == "((1 2) 3 4)"
774
- @nendo.evalStr( " (cons '(1 2) '((3 4))) " ).should == "((1 2) (3 4))"
775
- @nendo.evalStr( " (cons '() '()) " ).should == "(())"
776
- @nendo.evalStr( " (cons 1 '()) " ).should == "(1)"
777
- @nendo.evalStr( " (cons '() (cdr '(100))) " ).should == "(())"
778
- @nendo.evalStr( " (cons '() (car '(()))) " ).should == "(())"
779
- @nendo.evalStr( " (cons (car '(())) '()) " ).should == "(())"
780
- @nendo.evalStr( " (cons (car '(())) (car '(()))) " ).should == "(())"
781
- @nendo.evalStr( " (cons '() (cdr '(100))) " ).should == "(())"
782
- @nendo.evalStr( " (cons (cdr '(100)) '()) " ).should == "(())"
783
- @nendo.evalStr( " (cons (cdr '(100)) (cdr '(100))) " ).should == "(())"
784
- lambda { @nendo.evalStr( " (cons 1 2 3) " ) }.should raise_error(ArgumentError)
785
- lambda { @nendo.evalStr( " (cons 1) " ) }.should raise_error(ArgumentError)
786
- lambda { @nendo.evalStr( " (cons) " ) }.should raise_error(ArgumentError)
787
- @nendo.evalStr( " (list 1 2 3) " ).should == "(1 2 3)"
788
- @nendo.evalStr( " (list '(1) '(2) '(3)) " ).should == "((1) (2) (3))"
789
- @nendo.evalStr( " (list 'a 'b 'c) " ).should == "(a b c)"
790
- @nendo.evalStr( " (list '(a) '((b c))) " ).should == "((a) ((b c)))"
791
- @nendo.evalStr( " (list) " ).should == "()"
792
- @nendo.evalStr( " (list 1) " ).should == "(1)"
793
- @nendo.evalStr( " (reverse '(1)) " ).should == "(1)"
794
- @nendo.evalStr( " (reverse '(1 2 3)) " ).should == "(3 2 1)"
795
- @nendo.evalStr( " (reverse '(1 2 ())) " ).should == "(() 2 1)"
796
- @nendo.evalStr( " (reverse (list 1 2 (cdr '(100)))) " ).should == "(() 2 1)"
797
- @nendo.evalStr( " (define !a 10) !a" ).should == "10"
798
- @nendo.evalStr( " (define $a 11) $a" ).should == "11"
799
- @nendo.evalStr( " (define %a 12) %a" ).should == "12"
800
- @nendo.evalStr( " (define &a 13) &a" ).should == "13"
801
- @nendo.evalStr( " (define *a 14) *a" ).should == "14"
802
- @nendo.evalStr( " (define +a 15) +a" ).should == "15"
803
- @nendo.evalStr( " (define -a 16) -a" ).should == "16"
804
- @nendo.evalStr( " (define /a 17) /a" ).should == "17"
805
- @nendo.evalStr( " (define <a 18) <a" ).should == "18"
806
- @nendo.evalStr( " (define =a 19) =a" ).should == "19"
807
- @nendo.evalStr( " (define ?a 20) ?a" ).should == "20"
808
- @nendo.evalStr( " (define @a 21) @a" ).should == "21"
809
- @nendo.evalStr( " (define ^a 22) ^a" ).should == "22"
810
- @nendo.evalStr( " (define ~a 23) ~a" ).should == "23"
811
- @nendo.evalStr( " (define a! 30) a!" ).should == "30"
812
- @nendo.evalStr( " (define a$ 31) a$" ).should == "31"
813
- @nendo.evalStr( " (define a% 32) a%" ).should == "32"
814
- @nendo.evalStr( " (define a& 33) a&" ).should == "33"
815
- @nendo.evalStr( " (define a* 34) a*" ).should == "34"
816
- @nendo.evalStr( " (define a+ 35) a+" ).should == "35"
817
- @nendo.evalStr( " (define a- 36) a-" ).should == "36"
818
- @nendo.evalStr( " (define a/ 37) a/" ).should == "37"
819
- @nendo.evalStr( " (define a< 38) a<" ).should == "38"
820
- @nendo.evalStr( " (define a= 39) a=" ).should == "39"
821
- @nendo.evalStr( " (define a? 40) a?" ).should == "40"
822
- @nendo.evalStr( " (define a@ 41) a@" ).should == "41"
823
- @nendo.evalStr( " (define a^ 42) a^" ).should == "42"
824
- @nendo.evalStr( " (define a~ 43) a~" ).should == "43"
825
- @nendo.evalStr( " (define aFunc (lambda (x) x)) true" ).should == "#t"
826
- @nendo.evalStr( " (define aMacro (macro (x) x)) true" ).should == "#t"
827
- @nendo.evalStr( " (define a! 123) a!" ).should == "123"
828
- @nendo.evalStr( " (define b? 321) b?" ).should == "321"
829
- @nendo.evalStr( " (define a-b 1234) a-b" ).should == "1234"
830
- @nendo.evalStr( " (define start-end!? 4321) start-end!?" ).should == "4321"
831
- @nendo.evalStr( " (procedure? car) " ).should == "#t"
832
- @nendo.evalStr( " (procedure? aFunc) " ).should == "#t"
833
- @nendo.evalStr( " (procedure? aMacro) " ).should == "#f"
834
- @nendo.evalStr( " (procedure? 1) " ).should == "#f"
835
- @nendo.evalStr( " (procedure? 1.1) " ).should == "#f"
836
- @nendo.evalStr( " (procedure? \"str\") " ).should == "#f"
837
- @nendo.evalStr( " (procedure? 'a) " ).should == "#f"
838
- @nendo.evalStr( " (procedure? '(1)) " ).should == "#f"
839
- @nendo.evalStr( " (procedure? '()) " ).should == "#f"
840
- @nendo.evalStr( " (symbol? car) " ).should == "#f"
841
- @nendo.evalStr( " (symbol? aFunc) " ).should == "#f"
842
- @nendo.evalStr( " (symbol? aMacro) " ).should == "#f"
843
- @nendo.evalStr( " (symbol? 1) " ).should == "#f"
844
- @nendo.evalStr( " (symbol? 1.1) " ).should == "#f"
845
- @nendo.evalStr( " (symbol? \"str\") " ).should == "#f"
846
- @nendo.evalStr( " (symbol? 'a) " ).should == "#t"
847
- @nendo.evalStr( " (symbol? '(1)) " ).should == "#f"
848
- @nendo.evalStr( " (symbol? '()) " ).should == "#f"
849
- @nendo.evalStr( " (pair? car) " ).should == "#f"
850
- @nendo.evalStr( " (pair? aFunc) " ).should == "#f"
851
- @nendo.evalStr( " (pair? aMacro) " ).should == "#f"
852
- @nendo.evalStr( " (pair? 1) " ).should == "#f"
853
- @nendo.evalStr( " (pair? 1.1) " ).should == "#f"
854
- @nendo.evalStr( " (pair? \"str\") " ).should == "#f"
855
- @nendo.evalStr( " (pair? 'a) " ).should == "#f"
856
- @nendo.evalStr( " (pair? '(1)) " ).should == "#t"
857
- @nendo.evalStr( " (pair? '()) " ).should == "#f"
858
- @nendo.evalStr( " (number? car) " ).should == "#f"
859
- @nendo.evalStr( " (number? aFunc) " ).should == "#f"
860
- @nendo.evalStr( " (number? aMacro) " ).should == "#f"
861
- @nendo.evalStr( " (number? 1) " ).should == "#t"
862
- @nendo.evalStr( " (number? 1.1) " ).should == "#t"
863
- @nendo.evalStr( " (number? \"str\") " ).should == "#f"
864
- @nendo.evalStr( " (number? 'a) " ).should == "#f"
865
- @nendo.evalStr( " (number? '(1)) " ).should == "#f"
866
- @nendo.evalStr( " (number? '()) " ).should == "#f"
867
- @nendo.evalStr( " (integer? car) " ).should == "#f"
868
- @nendo.evalStr( " (integer? aFunc) " ).should == "#f"
869
- @nendo.evalStr( " (integer? aMacro) " ).should == "#f"
870
- @nendo.evalStr( " (integer? 1) " ).should == "#t"
871
- @nendo.evalStr( " (integer? 1.1) " ).should == "#f"
872
- @nendo.evalStr( " (integer? \"str\") " ).should == "#f"
873
- @nendo.evalStr( " (integer? 'a) " ).should == "#f"
874
- @nendo.evalStr( " (integer? '(1)) " ).should == "#f"
875
- @nendo.evalStr( " (integer? '()) " ).should == "#f"
876
- @nendo.evalStr( " (string? car) " ).should == "#f"
877
- @nendo.evalStr( " (string? aFunc) " ).should == "#f"
878
- @nendo.evalStr( " (string? aMacro) " ).should == "#f"
879
- @nendo.evalStr( " (string? 1) " ).should == "#f"
880
- @nendo.evalStr( " (string? 1.1) " ).should == "#f"
881
- @nendo.evalStr( " (string? \"str\") " ).should == "#t"
882
- @nendo.evalStr( " (string? 'a) " ).should == "#f"
883
- @nendo.evalStr( " (string? '(1)) " ).should == "#f"
884
- @nendo.evalStr( " (string? '()) " ).should == "#f"
885
- @nendo.evalStr( " (macro? car) " ).should == "#f"
886
- @nendo.evalStr( " (macro? aFunc) " ).should == "#f"
887
- @nendo.evalStr( " (macro? aMacro) " ).should == "#t"
888
- @nendo.evalStr( " (macro? 1) " ).should == "#f"
889
- @nendo.evalStr( " (macro? 1.1) " ).should == "#f"
890
- @nendo.evalStr( " (macro? \"str\") " ).should == "#f"
891
- @nendo.evalStr( " (macro? 'a) " ).should == "#f"
892
- @nendo.evalStr( " (macro? '(1)) " ).should == "#f"
893
- @nendo.evalStr( " (macro? '()) " ).should == "#f"
894
- @nendo.evalStr( " (length '()) " ).should == "0"
895
- @nendo.evalStr( " (length '(1)) " ).should == "1"
896
- @nendo.evalStr( " (length '((1))) " ).should == "1"
897
- @nendo.evalStr( " (length '(1 2)) " ).should == "2"
898
- lambda { @nendo.evalStr( " (length \"str\") " ) }.should raise_error(TypeError)
899
- lambda { @nendo.evalStr( " (length 1) " ) }.should raise_error(TypeError)
900
- @nendo.evalStr( " (symbol->string 'sym) " ).should == '"sym"'
901
- @nendo.evalStr( " (string->symbol \"sym\") " ).should == 'sym'
902
- @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") ) ' ).should == '"AaBbCc"'
903
- @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") ":") ' ).should == '"Aa:Bb:Cc"'
904
- @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") "//") ' ).should == '"Aa//Bb//Cc"'
905
- lambda { @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") 100) ' ) }.should raise_error(TypeError)
906
- lambda { @nendo.evalStr( ' (string-join \'("Aa" "Bb" "Cc") :xx) ' ) }.should raise_error(TypeError)
907
- @nendo.evalStr( ' (read-from-string "1") ' ).should == '1'
908
- @nendo.evalStr( ' (read-from-string "(+ 1 2)") ' ).should == '(+ 1 2)'
909
- @nendo.evalStr( ' (read-from-string "(\"Aa\" \"Bb\" \"Cc\")") ' ).should == '("Aa" "Bb" "Cc")'
910
- lambda { @nendo.evalStr( ' (read-from-string 100) ' ) }.should raise_error(TypeError)
911
- @nendo.evalStr( ' (write-to-string 1) ' ).should == '"1"'
912
- @nendo.evalStr( ' (write-to-string \'(+ 1 2)) ' ).should == '"(+ 1 2)"'
913
- @nendo.evalStr( ' (write-to-string \'("Aa" "Bb" "Cc")) ' ).should == '"(\"Aa\" \"Bb\" \"Cc\")"'
914
- end
915
- end
916
-
917
- describe Nendo, "when call evalStr() with variable modifications" do
918
- before do
919
- @nendo = Nendo::Core.new()
920
- end
921
- it "should" do
922
- @nendo.evalStr( " (define x 1) x " ).should == "1"
923
- @nendo.evalStr( " (define x 2) x " ).should == "2"
924
- @nendo.evalStr( " (define x 100) x " ).should == "100"
925
- @nendo.evalStr( " (define x true) x " ).should == "#t"
926
- @nendo.evalStr( " (define x false) x " ).should == "#f"
927
- @nendo.evalStr( " (define x nil) x " ).should == "nil"
928
- @nendo.evalStr( " (define x '()) x " ).should == "()"
929
- @nendo.evalStr( " (define x '(1)) x " ).should == "(1)"
930
- @nendo.evalStr( " (define x (+ 1 2 3)) x " ).should == "6"
931
- @nendo.evalStr( " (define x (sprintf \"$%02X\" 17)) x x x " ).should == '"$11"'
932
- @nendo.evalStr( " 1 2 3 " ).should == "3"
933
- @nendo.evalStr( " (define x 3.14) (set! x (* x 2)) x " ).should == "6.28"
934
- @nendo.evalStr( " 1 \n 2 \n 3 \n " ).should == "3"
935
- @nendo.evalStr( " (define a '(1 . 2)) (set-car! a 100) a " ).should == "(100 . 2)"
936
- @nendo.evalStr( " (define a '(1 . 2)) (set-car! a '()) a " ).should == "(() . 2)"
937
- @nendo.evalStr( " (define a '(1 . 2)) (set-car! a #t) a " ).should == "(#t . 2)"
938
- @nendo.evalStr( " (define a '(1 . 2)) (set-car! a #f) a " ).should == "(#f . 2)"
939
- @nendo.evalStr( " (define a '(1 . 2)) (set-car! a nil) a " ).should == "(nil . 2)"
940
- @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a 200) a " ).should == "(1 . 200)"
941
- @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a '(2)) a " ).should == "(1 2)"
942
- @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a '()) a " ).should == "(1)"
943
- @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a #t) a " ).should == "(1 . #t)"
944
- @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a #f) a " ).should == "(1 . #f)"
945
- @nendo.evalStr( " (define a '(1 . 2)) (set-cdr! a nil) a " ).should == "(1 . nil)"
946
- @nendo.evalStr( " (define a '((1 . 2) 3)) (set-car! (car a) 100) a " ).should == "((100 . 2) 3)"
947
- @nendo.evalStr( " (define a '((1 . 2) 3)) (set-cdr! (car a) 200) a " ).should == "((1 . 200) 3)"
948
- @nendo.evalStr( " (define a '((1 . 2) . 3)) (set-cdr! a 300) a " ).should == "((1 . 2) . 300)"
949
- end
950
- end
951
-
952
- describe Nendo, "when call evalStr() with undefined variable" do
953
- before do
954
- @nendo = Nendo::Core.new()
955
- @nendo.setDisplayErrors( false )
956
- end
957
- it "should" do
958
- lambda { @nendo.evalStr( " true " ) }.should_not raise_error
959
- lambda { @nendo.evalStr( " false " ) }.should_not raise_error
960
- lambda { @nendo.evalStr( " nil " ) }.should_not raise_error
961
- lambda { @nendo.evalStr( " line1 " ) }.should raise_error( NameError )
962
- lambda { @nendo.evalStr( " true \n line2 " ) }.should raise_error( NameError )
963
- lambda { @nendo.evalStr( " true \n true \n line3 " ) }.should raise_error( NameError )
964
- lambda { @nendo.evalStr( " (+ 1 x) " ) }.should raise_error( NameError )
965
- lambda { @nendo.evalStr( " true \n (+ 1 y) " ) }.should raise_error( NameError )
966
- end
967
- end
968
-
969
- describe Nendo, "when call evalStr() with built-in special forms" do
970
- before do
971
- @nendo = Nendo::Core.new()
972
- @nendo.setDisplayErrors( false )
973
- end
974
- it "should" do
975
- @nendo.evalStr( " (begin 1) " ).should == "1"
976
- @nendo.evalStr( " (begin 1 2) " ).should == "2"
977
- @nendo.evalStr( " (begin 1 2 3) " ).should == "3"
978
- @nendo.evalStr( <<EOS
979
- (set! x 2)
980
- (set! y (begin
981
- (set! x (* x 2))
982
- (set! x (* x 2))
983
- (set! x (* x 2))
984
- 100))
985
- (+ x y)
986
- EOS
987
- ).should == "116"
988
- @nendo.evalStr( " (%let () 100) " ).should == "100"
989
- @nendo.evalStr( " (%let ((a 11)) a) " ).should == "11"
990
- @nendo.evalStr( " (%let ((a 11) (b 22)) (+ a b)) " ).should == "33"
991
- @nendo.evalStr( " (%let ((a 22)) (%let ((b 33)) (+ a b))) " ).should == "55"
992
- @nendo.evalStr( " (%let ((a 22)(b 33)) (%let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
993
- @nendo.evalStr( " (%let ((a (%let ((b 2)) (+ 100 b)))) a) " ).should == "102"
994
- @nendo.evalStr( " (letrec () 100) " ).should == "100"
995
- @nendo.evalStr( " (letrec ((a 11)) a) " ).should == "11"
996
- @nendo.evalStr( " (letrec ((a 11) (b 22)) (+ a b)) " ).should == "33"
997
- @nendo.evalStr( " (letrec ((a 22)) (%let ((b 33)) (+ a b))) " ).should == "55"
998
- @nendo.evalStr( " (letrec ((a 22)(b 33)) (%let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
999
- @nendo.evalStr( " (letrec ((a (%let ((b 2)) (+ 100 b)))) a) " ).should == "102"
1000
- @nendo.evalStr( <<EOS
1001
- (letrec ((func1 (lambda () 13))
1002
- (func2 (lambda () (* 2 (func1)))))
1003
- (list (func2) (func1)))
1004
- EOS
1005
- ).should == "(26 13)"
1006
- @nendo.evalStr( <<EOS
1007
- (letrec ((func2 (lambda () (* 2 (func1))))
1008
- (func1 (lambda () 7)))
1009
- (list (func2) (func1)))
1010
- EOS
1011
- ).should == "(14 7)"
1012
- @nendo.evalStr( " (if true 't 'f)" ).should == "t"
1013
- @nendo.evalStr( " (if true '(1) '(2))" ).should == "(1)"
1014
- @nendo.evalStr( " (if false 't 'f)" ).should == "f"
1015
- @nendo.evalStr( " (if false '(1) '(2))" ).should == "(2)"
1016
- @nendo.evalStr( " (set! x 0) (if true (set! x 1) (set! x 2)) x" ).should == "1"
1017
- @nendo.evalStr( " (set! x 0) (if false (set! x 1) (set! x 2)) x" ).should == "2"
1018
- @nendo.evalStr( " (set! func (lambda (arg1) arg1)) (list (func 1) (func 2))" ).should == "(1 2)"
1019
- @nendo.evalStr( " ((lambda (arg1) arg1) 3)" ).should == "3"
1020
- @nendo.evalStr( " ((lambda (arg1) arg1) (+ 1 2 3))" ).should == "6"
1021
- @nendo.evalStr( " ((lambda (arg1 . arg2) arg1) 1 '(2))" ).should == "1"
1022
- @nendo.evalStr( " ((lambda (arg1 . arg2) arg2) 1 '(2))" ).should == "((2))"
1023
- @nendo.evalStr( " ((lambda (arg1 . arg2) arg2) 1 '(2 3))" ).should == "((2 3))"
1024
- @nendo.evalStr( " ((lambda (arg1 . arg2) arg1) '() '())" ).should == "()"
1025
- @nendo.evalStr( " ((lambda (arg1 . arg2) arg2) '() '())" ).should == "(())"
1026
- @nendo.evalStr( " ((lambda (arg1 . arg2) arg1) (cdr '(100)) (cdr '(200)))" ).should == "()"
1027
- @nendo.evalStr( " ((lambda (arg1 . arg2) arg2) (cdr '(100)) (cdr '(200)))" ).should == "(())"
1028
- @nendo.evalStr( " ((if #t + *) 3 4)" ).should == "7"
1029
- @nendo.evalStr( " ((if #f + *) 3 4)" ).should == "12"
1030
- @nendo.evalStr( " (apply1 + '(1 2))" ).should == "3"
1031
- @nendo.evalStr( " (apply1 + (range 10 1))" ).should == "55"
1032
- @nendo.evalStr( " (apply1 cons '(1 2))" ).should == "(1 . 2)"
1033
- @nendo.evalStr( " (apply1 list '(1 2 3))" ).should == "(1 2 3)"
1034
- lambda { @nendo.evalStr( " (error \"My Runtime Error\") " ) }.should raise_error( RuntimeError, /My Runtime Error/ )
1035
- lambda { @nendo.evalStr( " (error \"My Runtime Error\" '(a b c)) " ) }.should raise_error( RuntimeError, /My Runtime Error [(]a b c[)]/ )
1036
- @nendo.evalStr( "((lambda (arg1) (+ 1 arg1)) 2)" ).should == "3"
1037
- lambda { @nendo.evalStr( "((lambda (arg1) (+ 1 arg1)))" ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
1038
- end
1039
- end
1040
-
1041
- describe Nendo, "when call evalStr() with built-in special forms (renamed symbol)" do
1042
- before do
1043
- @nendo = Nendo::Core.new()
1044
- @nendo.setDisplayErrors( false )
1045
- @nendo.loadInitFile
1046
- end
1047
- it "should" do
1048
- @nendo.evalStr( " (/nendo/core/begin 1) " ).should == "1"
1049
- @nendo.evalStr( " (/nendo/core/begin 1 2) " ).should == "2"
1050
- @nendo.evalStr( " (/nendo/core/begin 1 2 3) " ).should == "3"
1051
- @nendo.evalStr( <<EOS
1052
- (/nendo/core/set! x 2)
1053
- (/nendo/core/set! y (/nendo/core/begin
1054
- (/nendo/core/set! x (* x 2))
1055
- (/nendo/core/set! x (* x 2))
1056
- (/nendo/core/set! x (* x 2))
1057
- 100))
1058
- (+ x y)
1059
- EOS
1060
- ).should == "116"
1061
- @nendo.evalStr( " (/nendo/core/%let () 100) " ).should == "100"
1062
- @nendo.evalStr( " (/nendo/core/%let ((a 11)) a) " ).should == "11"
1063
- @nendo.evalStr( " (/nendo/core/%let ((a 11) (b 22)) (+ a b)) " ).should == "33"
1064
- @nendo.evalStr( " (/nendo/core/%let ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
1065
- @nendo.evalStr( " (/nendo/core/%let ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
1066
- @nendo.evalStr( " (/nendo/core/%let ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
1067
- @nendo.evalStr( " (/nendo/core/letrec () 100) " ).should == "100"
1068
- @nendo.evalStr( " (/nendo/core/letrec ((a 11)) a) " ).should == "11"
1069
- @nendo.evalStr( " (/nendo/core/letrec ((a 11) (b 22)) (+ a b)) " ).should == "33"
1070
- @nendo.evalStr( " (/nendo/core/letrec ((a 22)) (let ((b 33)) (+ a b))) " ).should == "55"
1071
- @nendo.evalStr( " (/nendo/core/letrec ((a 22)(b 33)) (let ((c 44) (d 55)) (+ a b c d))) " ).should == "154"
1072
- @nendo.evalStr( " (/nendo/core/letrec ((a (let ((b 2)) (+ 100 b)))) a) " ).should == "102"
1073
- @nendo.evalStr( <<EOS
1074
- (/nendo/core/letrec ((func1 (/nendo/core/lambda () 13))
1075
- (func2 (/nendo/core/lambda () (* 2 (func1)))))
1076
- (list (func2) (func1)))
1077
- EOS
1078
- ).should == "(26 13)"
1079
- @nendo.evalStr( <<EOS
1080
- (/nendo/core/letrec ((func2 (/nendo/core/lambda () (* 2 (func1))))
1081
- (func1 (/nendo/core/lambda () 7)))
1082
- (list (func2) (func1)))
1083
- EOS
1084
- ).should == "(14 7)"
1085
- @nendo.evalStr( " (/nendo/core/if true 't 'f)" ).should == "t"
1086
- @nendo.evalStr( " (/nendo/core/if true '(1) '(2))" ).should == "(1)"
1087
- @nendo.evalStr( " (/nendo/core/if false 't 'f)" ).should == "f"
1088
- @nendo.evalStr( " (/nendo/core/if false '(1) '(2))" ).should == "(2)"
1089
- @nendo.evalStr( " (/nendo/core/set! x 0) (/nendo/core/if true (set! x 1) (set! x 2)) x" ).should == "1"
1090
- @nendo.evalStr( " (/nendo/core/set! x 0) (/nendo/core/if false (set! x 1) (set! x 2)) x" ).should == "2"
1091
- @nendo.evalStr( <<EOS
1092
- (/nendo/core/set! func (/nendo/core/lambda (arg1) arg1))
1093
- (list (func 1) (func 2))
1094
- EOS
1095
- ).should == "(1 2)"
1096
- @nendo.evalStr( " ((/nendo/core/lambda (arg1) arg1) 3)" ).should == "3"
1097
- @nendo.evalStr( " ((/nendo/core/lambda (arg1) arg1) (+ 1 2 3))" ).should == "6"
1098
- @nendo.evalStr( " ((/nendo/core/if #t + *) 3 4)" ).should == "7"
1099
- @nendo.evalStr( " ((/nendo/core/if #f + *) 3 4)" ).should == "12"
1100
- lambda { @nendo.evalStr( " (/nendo/core/error \"My Runtime Error\") " ) }.should raise_error( RuntimeError )
1101
- end
1102
- end
1103
-
1104
-
1105
- describe Nendo, "when redefined built-in functions(1)." do
1106
- before do
1107
- @nendo = Nendo::Core.new()
1108
- @nendo.setDisplayErrors( false )
1109
- @nendo.loadInitFile
1110
- end
1111
- it "should" do
1112
- @nendo.evalStr( " (define (+ a b) (list a b)) (+ 1 2)" ).should == "(1 2)"
1113
- lambda { @nendo.evalStr( " (define (+ a b) (list a b)) (+ 1 2 3)" ) }.should raise_error( ArgumentError )
1114
- @nendo.evalStr( " (define (eq? a b) \"eq?\") (eq? 1 1)" ).should == '"eq?"'
1115
- end
1116
- end
1117
-
1118
- describe Nendo, "when redefined built-in functions(2)." do
1119
- before do
1120
- @nendo = Nendo::Core.new()
1121
- @nendo.loadInitFile
1122
- end
1123
- it "should" do
1124
- @nendo.evalStr( " (define (< a b) \"<\") (< 1 1)" ).should == '"<"'
1125
- end
1126
- end
1127
-
1128
- describe Nendo, "when redefined built-in functions(3)." do
1129
- before do
1130
- @nendo = Nendo::Core.new()
1131
- @nendo.loadInitFile
1132
- end
1133
- it "should" do
1134
- @nendo.evalStr( " (define (car lst) \"car\") (car '(1 2))" ).should == '"car"'
1135
- end
1136
- end
1137
-
1138
- describe Nendo, "when call evalStr() with global and lexical scope variable" do
1139
- before do
1140
- @nendo = Nendo::Core.new()
1141
- end
1142
- it "should" do
1143
- @nendo.evalStr( " (define var 111) " ).should == "111"
1144
- @nendo.evalStr( " (%let ((var 222)) var) " ).should == "222"
1145
- @nendo.evalStr( " (%let ((var 222)) (set! var 333) var) " ).should == "333"
1146
- @nendo.evalStr( " (%let ((var 222)) (set! var 333)) var " ).should == "111"
1147
- @nendo.evalStr( " (define global1 \"G\") " ).should == '"G"'
1148
- @nendo.evalStr( <<EOS
1149
- (%let ((local1 \"L\")
1150
- (local2 \"L\"))
1151
- (set! global1 (+ global1 \"lobal1\"))
1152
- (set! local1 (+ local1 \"ocal1\"))
1153
- (set! local2 (+ local2 \"ocal2\"))
1154
- (list global1
1155
- local1
1156
- local2
1157
- (%let ((local1 \"A\")
1158
- (local2 \"B\"))
1159
- (set! local1 (+ local1 \"a\"))
1160
- (set! local2 (+ local2 \"b\"))
1161
- (list local1 local2
1162
- (%let ((local1 \"CCC\"))
1163
- (list global1 local1 local2))))))
1164
- EOS
1165
- ).should == '("Global1" "Local1" "Local2" ("Aa" "Bb" ("Global1" "CCC" "Bb")))'
1166
- end
1167
- end
1168
-
1169
- describe Nendo, "when call evalStr() with macroexpand-1 function" do
1170
- before do
1171
- @nendo = Nendo::Core.new()
1172
- end
1173
- it "should" do
1174
- @nendo.evalStr( <<EOS
1175
- (set! twice (macro (x) (list 'begin x x)))
1176
- (macroexpand-1 '(twice (+ 1 1)))
1177
- EOS
1178
- ).should == "(begin (+ 1 1) (+ 1 1))"
1179
- @nendo.evalStr( <<EOS
1180
- (set! inc (macro (x) (list 'set! x (list '+ x 1))))
1181
- (macroexpand-1 '(inc a))
1182
- EOS
1183
- ).should == "(set! a (+ a 1))"
1184
- @nendo.evalStr( " (set! a 10) (inc a) " ).should == "11"
1185
- @nendo.evalStr( " (set! a 10) (inc a) (inc a)" ).should == "12"
1186
- @nendo.evalStr( <<EOS
1187
- (macroexpand-1
1188
- '(twice (twice (inc a))))
1189
- EOS
1190
- ).should ==
1191
- "(begin (twice (inc a)) (twice (inc a)))"
1192
- @nendo.evalStr( <<EOS
1193
- (macroexpand-1
1194
- (macroexpand-1
1195
- '(twice (twice (inc a)))))
1196
- EOS
1197
- ).should ==
1198
- "(begin (begin (inc a) (inc a)) (twice (inc a)))"
1199
- @nendo.evalStr( <<EOS
1200
- (macroexpand-1
1201
- (macroexpand-1
1202
- (macroexpand-1
1203
- '(twice (twice (inc a))))))
1204
- EOS
1205
- ).should ==
1206
- "(begin (begin (set! a (+ a 1)) (inc a)) (twice (inc a)))"
1207
- @nendo.evalStr( <<EOS
1208
- (macroexpand-1
1209
- (macroexpand-1
1210
- (macroexpand-1
1211
- (macroexpand-1
1212
- '(twice (twice (inc a)))))))
1213
- EOS
1214
- ).should ==
1215
- "(begin (begin (set! a (+ a 1)) (set! a (+ a 1))) (twice (inc a)))"
1216
- @nendo.evalStr( " (set! a 10) (twice (twice (inc a)))" ).should == "14"
1217
- end
1218
- end
1219
-
1220
-
1221
- describe Nendo, "when use #xxxx syntax " do
1222
- before do
1223
- @nendo = Nendo::Core.new()
1224
- @nendo.setDisplayErrors( false )
1225
- @nendo.loadInitFile
1226
- end
1227
- it "should" do
1228
- @nendo.evalStr( " #t " ).should == "#t"
1229
- @nendo.evalStr( " #f " ).should == "#f"
1230
- @nendo.evalStr( " '#( 1 ) " ).should == "#(1)"
1231
- @nendo.evalStr( " '#() " ).should == "#()"
1232
- @nendo.evalStr( " #! \n #t" ).should == "#t"
1233
- @nendo.evalStr( " #! \n 100" ).should == "100"
1234
- @nendo.evalStr( " #! 123 \n 100" ).should == "100"
1235
- @nendo.evalStr( " '#?=1" ).should == "(debug-print 1 \"(string)\" 1 (quote 1))"
1236
- @nendo.evalStr( " '#?." ).should == '"(string):1"'
1237
- @nendo.evalStr( " '#?." ).should == '"(string):1"'
1238
- @nendo.evalStr( " (begin #?. (+ 1 1))" ).should == "2"
1239
- @nendo.evalStr( " (rxmatch #/[a-z]/ \"abc\")" ).should == "a"
1240
- @nendo.evalStr( " (quote #?=(rxmatch #/[a-z]/ \"abc\"))" ).should == '(debug-print (rxmatch #/[a-z]/ "abc") "(string)" 1 (quote (rxmatch #/[a-z]/ "abc")))'
1241
- @nendo.evalStr( <<EOS
1242
- (begin
1243
- #?.
1244
- (+ 1 1)
1245
- #?. )
1246
- EOS
1247
- ).should == '"(string):4"'
1248
- @nendo.evalStr( " #b0 " ).should == Integer("0b0").to_s
1249
- @nendo.evalStr( " #b01 " ).should == Integer("0b01").to_s
1250
- @nendo.evalStr( " #b10 " ).should == Integer("0b10").to_s
1251
- @nendo.evalStr( " #b00000001 " ).should == Integer("0b00000001").to_s
1252
- @nendo.evalStr( " #b1010101010101010 " ).should == Integer("0b1010101010101010").to_s
1253
- lambda { @nendo.evalStr( " #b2 " ) }.should raise_error(RuntimeError)
1254
- lambda { @nendo.evalStr( " #b02 " ) }.should raise_error(RuntimeError)
1255
- lambda { @nendo.evalStr( " #bF " ) }.should raise_error(RuntimeError)
1256
- @nendo.evalStr( " #o0 " ).should == Integer("0o0").to_s
1257
- @nendo.evalStr( " #o7 " ).should == Integer("0o7").to_s
1258
- @nendo.evalStr( " #o01 " ).should == Integer("0o01").to_s
1259
- @nendo.evalStr( " #o10 " ).should == Integer("0o10").to_s
1260
- @nendo.evalStr( " #o777 " ).should == Integer("0o777").to_s
1261
- @nendo.evalStr( " #o00000007 " ).should == Integer("0o00000007").to_s
1262
- @nendo.evalStr( " #o0123456701234567 " ).should == Integer("0o0123456701234567").to_s
1263
- lambda { @nendo.evalStr( " #o8 " ) }.should raise_error(RuntimeError)
1264
- lambda { @nendo.evalStr( " #o08 " ) }.should raise_error(RuntimeError)
1265
- lambda { @nendo.evalStr( " #oA " ) }.should raise_error(RuntimeError)
1266
- @nendo.evalStr( " #d0 " ).should == Integer("0d0").to_s
1267
- @nendo.evalStr( " #d9 " ).should == Integer("0d9").to_s
1268
- @nendo.evalStr( " #d01 " ).should == Integer("0d01").to_s
1269
- @nendo.evalStr( " #d10 " ).should == Integer("0d10").to_s
1270
- @nendo.evalStr( " #d999 " ).should == Integer("0d999").to_s
1271
- @nendo.evalStr( " #d00000009 " ).should == Integer("0d00000009").to_s
1272
- @nendo.evalStr( " #d0123456701234567 " ).should == Integer("0d0123456701234567").to_s
1273
- lambda { @nendo.evalStr( " #dA " ) }.should raise_error(RuntimeError)
1274
- lambda { @nendo.evalStr( " #dF " ) }.should raise_error(RuntimeError)
1275
- @nendo.evalStr( " #x0 " ).should == Integer("0x0").to_s
1276
- @nendo.evalStr( " #x9 " ).should == Integer("0x9").to_s
1277
- @nendo.evalStr( " #xA " ).should == Integer("0xA").to_s
1278
- @nendo.evalStr( " #xF " ).should == Integer("0xF").to_s
1279
- @nendo.evalStr( " #x01 " ).should == Integer("0x01").to_s
1280
- @nendo.evalStr( " #x10 " ).should == Integer("0x10").to_s
1281
- @nendo.evalStr( " #xFFF " ).should == Integer("0xFFF").to_s
1282
- @nendo.evalStr( " #x0000000F " ).should == Integer("0x0000000F").to_s
1283
- @nendo.evalStr( " #x0123456789ABCDEF0123456789ABCDEF " ).should == Integer("0x0123456789ABCDEF0123456789ABCDEF").to_s
1284
- lambda { @nendo.evalStr( " #xg " ) }.should raise_error(RuntimeError)
1285
- lambda { @nendo.evalStr( " #xh " ) }.should raise_error(RuntimeError)
1286
- lambda { @nendo.evalStr( " #xz " ) }.should raise_error(RuntimeError)
1287
- lambda { @nendo.evalStr( " #xG " ) }.should raise_error(RuntimeError)
1288
- lambda { @nendo.evalStr( " #xH " ) }.should raise_error(RuntimeError)
1289
- lambda { @nendo.evalStr( " #xZ " ) }.should raise_error(RuntimeError)
1290
- lambda { @nendo.evalStr( " #a " ) }.should raise_error(NameError)
1291
- lambda { @nendo.evalStr( " #c " ) }.should raise_error(NameError)
1292
- lambda { @nendo.evalStr( " #e " ) }.should raise_error(NameError)
1293
- lambda { @nendo.evalStr( " #tt " ) }.should raise_error(NameError)
1294
- lambda { @nendo.evalStr( " #ff " ) }.should raise_error(NameError)
1295
- lambda { @nendo.evalStr( " #abc " ) }.should raise_error(NameError)
1296
- lambda { @nendo.evalStr( " #? " ) }.should raise_error(NameError)
1297
- lambda { @nendo.evalStr( " #?a " ) }.should raise_error(NameError)
1298
- lambda { @nendo.evalStr( " #= " ) }.should raise_error(NameError)
1299
- lambda { @nendo.evalStr( " #?? " ) }.should raise_error(NameError)
1300
- end
1301
- end
1302
-
1303
- describe Nendo, "when use regexp litteral and library functions " do
1304
- before do
1305
- @nendo = Nendo::Core.new()
1306
- @nendo.setDisplayErrors( false )
1307
- @nendo.loadInitFile
1308
- end
1309
- it "should" do
1310
- @nendo.evalStr( " #/abc/ " ).should == "#/abc/"
1311
- @nendo.evalStr( " #/[a-z]/ " ).should == "#/[a-z]/"
1312
- @nendo.evalStr( " #/[a-zA-Z0-9]+/ " ).should == "#/[a-zA-Z0-9]+/"
1313
- @nendo.evalStr( ' #/\d/ ' ).should == '#/\d/'
1314
- @nendo.evalStr( ' #/[\/]/ ' ).should == '#/[\/]/'
1315
- @nendo.evalStr( ' #/\]/ ' ).should == '#/\]/'
1316
- @nendo.evalStr( ' #/^\]/ ' ).should == '#/^\]/'
1317
- @nendo.evalStr( ' #/\[/ ' ).should == '#/\[/'
1318
- @nendo.evalStr( ' #/^\[/ ' ).should == '#/^\[/'
1319
- @nendo.evalStr( ' #/\.\^\$\/\+\-\(\)\|/ ' ).should == '#/\.\^\$\/\+\-\(\)\|/'
1320
- @nendo.evalStr( " #/abc/i " ).should == "#/abc/i"
1321
- @nendo.evalStr( " #/[a-z]/i " ).should == "#/[a-z]/i"
1322
- lambda { @nendo.evalStr( " #/[a-z]/I " ) }.should raise_error(NameError)
1323
- lambda { @nendo.evalStr( " #/[a-z]/a " ) }.should raise_error(NameError)
1324
-
1325
- @nendo.evalStr( ' (string->regexp "abc") ' ).should == '#/abc/'
1326
- @nendo.evalStr( ' (string->regexp "[a-z]") ' ).should == '#/[a-z]/'
1327
- @nendo.evalStr( ' (string->regexp "[a-zA-Z0-9]+" ) ' ).should == '#/[a-zA-Z0-9]+/'
1328
- @nendo.evalStr( ' (string->regexp "\\\\d" ) ' ).should == '#/\d/'
1329
- @nendo.evalStr( " (regexp? #/str/ ) " ).should == "#t"
1330
- @nendo.evalStr( " (regexp? #/str/i ) " ).should == "#t"
1331
- @nendo.evalStr( " (regexp? \"str\" ) " ).should == "#f"
1332
- @nendo.evalStr( " (regexp? 'str) " ).should == "#f"
1333
- @nendo.evalStr( " (regexp? (. \"str\" intern)) " ).should == "#f"
1334
- @nendo.evalStr( " (regexp? 100) " ).should == "#f"
1335
-
1336
- @nendo.evalStr( " (regexp->string #/abc/ ) " ).should == '"abc"'
1337
- @nendo.evalStr( " (regexp->string #/[a-z]/ ) " ).should == '"[a-z]"'
1338
- @nendo.evalStr( " (regexp->string #/[a-zA-Z0-9]+/ ) " ).should == '"[a-zA-Z0-9]+"'
1339
- @nendo.evalStr( ' (regexp->string #/\d+/ ) ' ).should == '"\\\\d+"'
1340
-
1341
- @nendo.evalStr( ' (define matchdata (rxmatch #/(\d+):(\d+)/ "foo314:2000bar")) ' ).should == '314:2000'
1342
- @nendo.evalStr( ' (rxmatch-start matchdata) ' ).should == '3'
1343
- @nendo.evalStr( ' (rxmatch-start matchdata 0) ' ).should == '3'
1344
- @nendo.evalStr( ' (rxmatch-start matchdata 1) ' ).should == '3'
1345
- @nendo.evalStr( ' (rxmatch-start matchdata 2) ' ).should == '7'
1346
- @nendo.evalStr( ' (rxmatch-end matchdata) ' ).should == '11'
1347
- @nendo.evalStr( ' (rxmatch-end matchdata 0) ' ).should == '11'
1348
- @nendo.evalStr( ' (rxmatch-end matchdata 1) ' ).should == '6'
1349
- @nendo.evalStr( ' (rxmatch-end matchdata 2) ' ).should == '11'
1350
- @nendo.evalStr( ' (rxmatch-substring matchdata) ' ).should == '"314:2000"'
1351
- @nendo.evalStr( ' (rxmatch-substring matchdata 0) ' ).should == '"314:2000"'
1352
- @nendo.evalStr( ' (rxmatch-substring matchdata 1) ' ).should == '"314"'
1353
- @nendo.evalStr( ' (rxmatch-substring matchdata 2) ' ).should == '"2000"'
1354
- @nendo.evalStr( ' (rxmatch-num-matches matchdata) ' ).should == '3'
1355
-
1356
- @nendo.evalStr( ' (define matchdata (rxmatch #/(\w+)@([\w.]+)/ "foo@example.com")) ' ).should == 'foo@example.com'
1357
- @nendo.evalStr( ' (rxmatch-substring matchdata) ' ).should == '"foo@example.com"'
1358
- @nendo.evalStr( ' (rxmatch-substring matchdata 0) ' ).should == '"foo@example.com"'
1359
- @nendo.evalStr( ' (rxmatch-substring matchdata 1) ' ).should == '"foo"'
1360
- @nendo.evalStr( ' (rxmatch-substring matchdata 2) ' ).should == '"example.com"'
1361
-
1362
- @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com")' ).should == '"foo@example.com"'
1363
- @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com" 0)' ).should == '"foo@example.com"'
1364
- @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com" 1)' ).should == '"foo"'
1365
- @nendo.evalStr( ' (rxmatch->string #/(\w+)@([\w.]+)/ "foo@example.com" 2)' ).should == '"example.com"'
1366
-
1367
- @nendo.evalStr( ' (rxmatch->string #/abc/ "000abc00ABC000")' ).should == '"abc"'
1368
- @nendo.evalStr( ' (rxmatch->string #/ABC/ "000abc00ABC000")' ).should == '"ABC"'
1369
- @nendo.evalStr( ' (rxmatch->string #/abc/i "abc")' ).should == '"abc"'
1370
- @nendo.evalStr( ' (rxmatch->string #/abc/i "ABC")' ).should == '"ABC"'
1371
- @nendo.evalStr( ' (rxmatch->string #/ABC/i "abc")' ).should == '"abc"'
1372
- @nendo.evalStr( ' (rxmatch->string #/abc/i "AbC")' ).should == '"AbC"'
1373
-
1374
- @nendo.evalStr( ' (rxmatch #/abc/i "xxx")' ).should == '#f'
1375
- @nendo.evalStr( ' (rxmatch #/XXX/ "xxx")' ).should == '#f'
1376
- @nendo.evalStr( ' (rxmatch->string #/abc/i "xxx")' ).should == '#f'
1377
- @nendo.evalStr( ' (rxmatch->string #/XXX/ "xxx")' ).should == '#f'
1378
-
1379
- pending( "JRuby can't compute correctly" ) if defined? JRUBY_VERSION
1380
- @nendo.evalStr( <<EOS
1381
- (define matchdata
1382
- (rxmatch #/([あ-ん])([あ-ん])([あ-ん])([あ-ん])([あ-ん])/
1383
- "ABC漢字あいうえお漢字ABC"))
1384
- EOS
1385
- ).should == 'あいうえお'
1386
- @nendo.evalStr( ' (rxmatch-start matchdata) ' ).should == '5'
1387
- @nendo.evalStr( ' (rxmatch-end matchdata) ' ).should == '10'
1388
- @nendo.evalStr( ' (rxmatch-substring matchdata) ' ).should == '"あいうえお"'
1389
- @nendo.evalStr( ' (rxmatch-substring matchdata 1) ' ).should == '"あ"'
1390
- @nendo.evalStr( ' (rxmatch-substring matchdata 2) ' ).should == '"い"'
1391
- @nendo.evalStr( ' (rxmatch-substring matchdata 3) ' ).should == '"う"'
1392
- end
1393
- end
1394
-
1395
-
1396
- describe Nendo, "when call functions in init.nnd " do
1397
- before do
1398
- @nendo = Nendo::Core.new()
1399
- @nendo.loadInitFile
1400
- @nendo.loadInitFile # to self optimizing. The init.nnd file will be loaded twice, so `map' can be optimized on second loading phase.
1401
- end
1402
- it "should" do
1403
- @nendo.evalStr( " (cadr '(1 2 3 4)) " ).should == "2"
1404
- @nendo.evalStr( " (caddr '(1 2 3 4)) " ).should == "3"
1405
- @nendo.evalStr( " (cadddr '(1 2 3 4)) " ).should == "4"
1406
- @nendo.evalStr( " (caar '((5 6 7 8))) " ).should == "5"
1407
- @nendo.evalStr( " (cdar '((5 6 7 8))) " ).should == "(6 7 8)"
1408
- @nendo.evalStr( " (cadar '((5 6 7 8))) " ).should == "6"
1409
- @nendo.evalStr( " (cddar '((5 6 7 8))) " ).should == "(7 8)"
1410
- @nendo.evalStr( " (iota 1) " ).should == "(0)"
1411
- @nendo.evalStr( " (iota 3) " ).should == "(0 1 2)"
1412
- @nendo.evalStr( " (append '() '()) " ).should == "()"
1413
- @nendo.evalStr( " (append '(1) '()) " ).should == "(1)"
1414
- @nendo.evalStr( " (append '() '(2)) " ).should == "(2)"
1415
- @nendo.evalStr( " (append '(1) '(2)) " ).should == "(1 2)"
1416
- @nendo.evalStr( " (append '(1 2) '(3 4)) " ).should == "(1 2 3 4)"
1417
- @nendo.evalStr( " (append '(1 2) (cdr '(200))) " ).should == "(1 2)"
1418
- @nendo.evalStr( " (append (cdr '(100)) '(10 20)) " ).should == "(10 20)"
1419
- @nendo.evalStr( " (define lst '()) " ).should == "()"
1420
- @nendo.evalStr( " (push! lst 1) " ).should == "(1)"
1421
- @nendo.evalStr( " lst " ).should == "(1)"
1422
- @nendo.evalStr( " (push! lst 2) " ).should == "(2 1)"
1423
- @nendo.evalStr( " lst " ).should == "(2 1)"
1424
- @nendo.evalStr( " (push! lst 3) " ).should == "(3 2 1)"
1425
- @nendo.evalStr( " lst " ).should == "(3 2 1)"
1426
- @nendo.evalStr( ' (push! lst "str") ' ).should == '("str" 3 2 1)'
1427
- @nendo.evalStr( " lst " ).should == '("str" 3 2 1)'
1428
- @nendo.evalStr( " (pair? '()) " ).should == "#f"
1429
- @nendo.evalStr( " (pair? '(1)) " ).should == "#t"
1430
- @nendo.evalStr( " (pair? '(1 2)) " ).should == "#t"
1431
- @nendo.evalStr( " (pair? '(1 2 3)) " ).should == "#t"
1432
- @nendo.evalStr( " (pair? '(1 . 2)) " ).should == "#t"
1433
- @nendo.evalStr( " (pair? '(())) " ).should == "#t"
1434
- @nendo.evalStr( " (pair? 1) " ).should == "#f"
1435
- @nendo.evalStr( " (pair? \"str\") " ).should == "#f"
1436
- @nendo.evalStr( " (list? '()) " ).should == "#t"
1437
- @nendo.evalStr( " (list? '(1)) " ).should == "#t"
1438
- @nendo.evalStr( " (list? '(1 2)) " ).should == "#t"
1439
- @nendo.evalStr( " (list? '(1 2 3)) " ).should == "#t"
1440
- @nendo.evalStr( " (list? '(1 . 2)) " ).should == "#f"
1441
- @nendo.evalStr( " (list? '(1 2 . 3)) " ).should == "#f"
1442
- @nendo.evalStr( " (list? '(())) " ).should == "#t"
1443
- @nendo.evalStr( " (list? 1) " ).should == "#f"
1444
- @nendo.evalStr( " (list? \"str\") " ).should == "#f"
1445
- @nendo.evalStr( " (even? 2) " ).should == "#t"
1446
- @nendo.evalStr( " (even? 1) " ).should == "#f"
1447
- @nendo.evalStr( " (even? 0) " ).should == "#t"
1448
- @nendo.evalStr( " (even? -1) " ).should == "#f"
1449
- @nendo.evalStr( " (even? -2) " ).should == "#t"
1450
- @nendo.evalStr( " (odd? 2) " ).should == "#f"
1451
- @nendo.evalStr( " (odd? 1) " ).should == "#t"
1452
- @nendo.evalStr( " (odd? 0) " ).should == "#f"
1453
- @nendo.evalStr( " (odd? -1) " ).should == "#t"
1454
- @nendo.evalStr( " (odd? -2) " ).should == "#f"
1455
- @nendo.evalStr( " (zero? 0) " ).should == "#t"
1456
- @nendo.evalStr( " (zero? #f) " ).should == "#f"
1457
- @nendo.evalStr( " (zero? #t) " ).should == "#f"
1458
- @nendo.evalStr( " (zero? 1) " ).should == "#f"
1459
- @nendo.evalStr( " (zero? 2) " ).should == "#f"
1460
- @nendo.evalStr( " (zero? -1) " ).should == "#f"
1461
- @nendo.evalStr( " (zero? \"str\") " ).should == "#f"
1462
- @nendo.evalStr( " (zero? zero?) " ).should == "#f"
1463
- @nendo.evalStr( " (positive? 1) " ).should == "#t"
1464
- @nendo.evalStr( " (positive? 0) " ).should == "#f"
1465
- @nendo.evalStr( " (positive? -1) " ).should == "#f"
1466
- @nendo.evalStr( " (negative? 1) " ).should == "#f"
1467
- @nendo.evalStr( " (negative? 0) " ).should == "#f"
1468
- @nendo.evalStr( " (negative? -1) " ).should == "#t"
1469
- @nendo.evalStr( " (abs -1) " ).should == "1"
1470
- @nendo.evalStr( " (abs 1) " ).should == "1"
1471
- @nendo.evalStr( " (abs -1000) " ).should == "1000"
1472
- @nendo.evalStr( " (abs 1000) " ).should == "1000"
1473
- @nendo.evalStr( " (max -2 1 0 1 2 3 4 5) " ).should == "5"
1474
- @nendo.evalStr( " (max 5 4 3 2 1 0 -1 -2) " ).should == "5"
1475
- @nendo.evalStr( " (max 1000000000 10 -10000) " ).should == "1000000000"
1476
- @nendo.evalStr( " (min -2 1 0 1 2 3 4 5) " ).should == "-2"
1477
- @nendo.evalStr( " (min 5 4 3 2 1 0 -1 -2) " ).should == "-2"
1478
- @nendo.evalStr( " (min 1000000000 10 -10000) " ).should == "-10000"
1479
- @nendo.evalStr( " (succ -1) " ).should == "0"
1480
- @nendo.evalStr( " (succ 0) " ).should == "1"
1481
- @nendo.evalStr( " (succ 1) " ).should == "2"
1482
- @nendo.evalStr( " (pred -1) " ).should == "-2"
1483
- @nendo.evalStr( " (pred 0) " ).should == "-1"
1484
- @nendo.evalStr( " (pred 1) " ).should == "0"
1485
- @nendo.evalStr( " (pred 2) " ).should == "1"
1486
- @nendo.evalStr( " (min 1000000000 10 -10000) " ).should == "-10000"
1487
- @nendo.evalStr( " (nth 0 '(100 200 300)) " ).should == "100"
1488
- @nendo.evalStr( " (nth 1 '(100 200 300)) " ).should == "200"
1489
- @nendo.evalStr( " (nth 2 '(100 200 300)) " ).should == "300"
1490
- @nendo.evalStr( " (nth 3 '(100 200 300)) " ).should == "()"
1491
- @nendo.evalStr( " (nth -1 '(100 200 300)) " ).should == "()"
1492
- @nendo.evalStr( " (first '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "100"
1493
- @nendo.evalStr( " (second '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "200"
1494
- @nendo.evalStr( " (third '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "300"
1495
- @nendo.evalStr( " (fourth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "400"
1496
- @nendo.evalStr( " (fifth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "500"
1497
- @nendo.evalStr( " (sixth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "600"
1498
- @nendo.evalStr( " (seventh '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "700"
1499
- @nendo.evalStr( " (eighth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "800"
1500
- @nendo.evalStr( " (ninth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "900"
1501
- @nendo.evalStr( " (tenth '(100 200 300 400 500 600 700 800 900 1000)) " ).should == "1000"
1502
- @nendo.evalStr( " (first '()) " ).should == "()"
1503
- @nendo.evalStr( " (tenth '()) " ).should == "()"
1504
- @nendo.evalStr( " (to-s 10) " ).should == '"10"'
1505
- @nendo.evalStr( " (to_s 10) " ).should == '"10"'
1506
- @nendo.evalStr( " (x->string 10) " ).should == '"10"'
1507
- @nendo.evalStr( " (number->string 11) " ).should == '"11"'
1508
- @nendo.evalStr( " (to-s 2.1) " ).should == '"2.1"'
1509
- @nendo.evalStr( " (to_s 2.1) " ).should == '"2.1"'
1510
- @nendo.evalStr( " (x->string 2.1) " ).should == '"2.1"'
1511
- @nendo.evalStr( " (number->string 2.2) " ).should == '"2.2"'
1512
- @nendo.evalStr( ' (string-append) ' ).should == '""'
1513
- @nendo.evalStr( ' (string-append "a") ' ).should == '"a"'
1514
- @nendo.evalStr( ' (string-append "a" "b") ' ).should == '"ab"'
1515
- @nendo.evalStr( ' (string-append "a" "B" "c" "D" "e") ' ).should == '"aBcDe"'
1516
- @nendo.evalStr( ' (string=? "ABC" "ABC") ' ).should == '#t'
1517
- @nendo.evalStr( ' (string=? "ABC" "ABc") ' ).should == '#f'
1518
- @nendo.evalStr( ' (string=? "ABC" "abc") ' ).should == '#f'
1519
- @nendo.evalStr( ' (string=? 100 100) ' ).should == '#t'
1520
- @nendo.evalStr( ' (string=? (+ "A" "B") "AB") ' ).should == '#t'
1521
- @nendo.evalStr( " (to_i \"22\") " ).should == '22'
1522
- @nendo.evalStr( " (to-i \"22\") " ).should == '22'
1523
- @nendo.evalStr( " (to_i \"10000\") " ).should == '10000'
1524
- @nendo.evalStr( " (to-i \"10000\") " ).should == '10000'
1525
- @nendo.evalStr( " (let1 aaa 111 aaa) " ).should == "111"
1526
- @nendo.evalStr( " (let1 aaa (+ 2 3) aaa) " ).should == "5"
1527
- @nendo.evalStr( " (let1 aaa 333 (let1 bbb 444 (+ aaa bbb))) " ).should == "777"
1528
- @nendo.evalStr( " (let1 aaa 333 (let1 bbb 444 (set! bbb 555) (+ aaa bbb))) " ).should == "888"
1529
- @nendo.evalStr( " (memq 'b '(a b c d)) " ).should == "(b c d)"
1530
- @nendo.evalStr( " (memq 'c '(a b c d)) " ).should == "(c d)"
1531
- @nendo.evalStr( " (memq 'd '(a b c d)) " ).should == "(d)"
1532
- @nendo.evalStr( " (memq 'e '(a b c d)) " ).should == "#f"
1533
- @nendo.evalStr( " (memq 'e '(a b c d . e)) " ).should == "#f"
1534
- @nendo.evalStr( ' (memq "b" \'("a" "b" "c" "d")) ' ).should == '("b" "c" "d")'
1535
- @nendo.evalStr( ' (memv "b" \'("a" "b" "c" "d")) ' ).should == '("b" "c" "d")'
1536
- @nendo.evalStr( ' (memv "c" \'("a" "b" "c" "d")) ' ).should == '("c" "d")'
1537
- @nendo.evalStr( ' (memv "d" \'("a" "b" "c" "d")) ' ).should == '("d")'
1538
- @nendo.evalStr( ' (memv "e" \'("a" "b" "c" "d")) ' ).should == '#f'
1539
- @nendo.evalStr( ' (memv "e" \'("a" "b" "c" "d" . "e")) ' ).should == '#f'
1540
- @nendo.evalStr( ' (memv \'("b") \'(("a") ("b") ("c") ("d"))) ' ).should == '#f'
1541
- @nendo.evalStr( ' (member \'("b") \'(("a") ("b") ("c") ("d"))) ' ).should == '(("b") ("c") ("d"))'
1542
- @nendo.evalStr( ' (member \'("c") \'(("a") ("b") ("c") ("d"))) ' ).should == '(("c") ("d"))'
1543
- @nendo.evalStr( ' (member \'("d") \'(("a") ("b") ("c") ("d"))) ' ).should == '(("d"))'
1544
- @nendo.evalStr( ' (member \'("e") \'(("a") ("b") ("c") ("d"))) ' ).should == '#f'
1545
- @nendo.evalStr( ' (member \'("e") \'(("a") ("b") ("c") ("d") . ("e"))) ' ).should == '#f'
1546
- @nendo.evalStr( " (let1 v (map (lambda (x) x) '(1 2 3)) v) " ).should == "(1 2 3)"
1547
- @nendo.evalStr( " (let ((v (map (lambda (x) x) '(1 2 3)))) v) " ).should == "(1 2 3)"
1548
- @nendo.evalStr( " (cond (true 1) (false 2)) " ).should == "1"
1549
- @nendo.evalStr( " (cond (true ) (false )) " ).should == "#t"
1550
- @nendo.evalStr( " (cond (false 1) (true 2)) " ).should == "2"
1551
- @nendo.evalStr( " (cond (true 1) (true 2)) " ).should == "1"
1552
- @nendo.evalStr( " (cond (false 1) (false 2)) " ).should == "()"
1553
- @nendo.evalStr( " (cond (false 1) (false 2) (else 3)) " ).should == "3"
1554
- @nendo.evalStr( <<EOS
1555
- (cond
1556
- ((- 10 9)
1557
- =>
1558
- (lambda (x)
1559
- (+ \"<\" (to_s x) \">\")))
1560
- (else
1561
- 2))
1562
- EOS
1563
- ).should == '"<1>"'
1564
- @nendo.evalStr( <<EOS
1565
- (cond
1566
- (true 1)
1567
- ((- 10 8)
1568
- =>
1569
- (lambda (x)
1570
- (+ \"<\" (to_s x) \">\")))
1571
- (else
1572
- 3))
1573
- EOS
1574
- ).should == "1"
1575
- @nendo.evalStr( " (or) " ).should == "#f"
1576
- @nendo.evalStr( " (or true) " ).should == "#t"
1577
- @nendo.evalStr( " (or false) " ).should == "#f"
1578
- @nendo.evalStr( " (or nil) " ).should == "#f"
1579
- @nendo.evalStr( " (or '(1)) " ).should == "(1)"
1580
- @nendo.evalStr( " (or '()) " ).should == "()"
1581
- @nendo.evalStr( " (or true true true) " ).should == "#t"
1582
- @nendo.evalStr( " (or 1 2 3) " ).should == "1"
1583
- @nendo.evalStr( " (or false 2) " ).should == "2"
1584
- @nendo.evalStr( " (or false false 3) " ).should == "3"
1585
- @nendo.evalStr( " (or false '(2) false) " ).should == "(2)"
1586
- @nendo.evalStr( " (and) " ).should == "#t"
1587
- @nendo.evalStr( " (and true) " ).should == "#t"
1588
- @nendo.evalStr( " (and false) " ).should == "#f"
1589
- @nendo.evalStr( " (and nil) " ).should == "nil"
1590
- @nendo.evalStr( " (and '(1)) " ).should == "(1)"
1591
- @nendo.evalStr( " (and '()) " ).should == "()"
1592
- @nendo.evalStr( " (and true true true) " ).should == "#t"
1593
- @nendo.evalStr( " (and 1 2 3) " ).should == "3"
1594
- @nendo.evalStr( " (and false 2) " ).should == "#f"
1595
- @nendo.evalStr( " (and false false 3) " ).should == "#f"
1596
- @nendo.evalStr( " (and true 2) " ).should == "2"
1597
- @nendo.evalStr( " (and true true 3) " ).should == "3"
1598
- @nendo.evalStr( " (and true true 3 false) " ).should == "#f"
1599
- @nendo.evalStr( " (and true '(2) true) " ).should == "#t"
1600
- @nendo.evalStr( " (and true true '(2)) " ).should == "(2)"
1601
- @nendo.evalStr( " (and true '(2) false) " ).should == "#f"
1602
- @nendo.evalStr( <<EOS
1603
- (define total 0)
1604
- (and 1
1605
- 2
1606
- (set! total (+ total 1))
1607
- (set! total (+ total 2))
1608
- 5)
1609
- total
1610
- EOS
1611
- ).should == "3"
1612
- @nendo.evalStr( <<EOS
1613
- (define total 1)
1614
- (and 1
1615
- 2
1616
- false
1617
- (set! total (+ total 2))
1618
- (set! total (+ total 3))
1619
- 5)
1620
- total
1621
- EOS
1622
- ).should == "1"
1623
- @nendo.evalStr( " (apply + 100 '()) " ).should == "100"
1624
- @nendo.evalStr( " (apply + '(1 2)) " ).should == "3"
1625
- @nendo.evalStr( " (apply + 1 2 '(3)) " ).should == "6"
1626
- @nendo.evalStr( " (apply + 1 2 '(3 4)) " ).should == "10"
1627
- @nendo.evalStr( " (apply + 1 2 3 '(4)) " ).should == "10"
1628
- @nendo.evalStr( ' (apply + \'("a" "b" "c")) ' ).should == '"abc"'
1629
- @nendo.evalStr( " (range 5) " ).should == "(0 1 2 3 4)"
1630
- @nendo.evalStr( " (range 5 1) " ).should == "(1 2 3 4 5)"
1631
- @nendo.evalStr( " (range 5 2) " ).should == "(2 3 4 5 6)"
1632
- @nendo.evalStr( " (iota 5 2) " ).should == "(2 3 4 5 6)"
1633
- @nendo.evalStr( " (apply + (range 11)) " ).should == "55"
1634
- @nendo.evalStr( " (apply + (map (lambda (x) (+ x 1)) (range 10))) " ).should == "55"
1635
- @nendo.evalStr( " (apply + (append (range 11) '(100))) " ).should == "155"
1636
- @nendo.evalStr( " (apply cons '(1 2)) " ).should == "(1 . 2)"
1637
- @nendo.evalStr( " (apply list '(1 2)) " ).should == "(1 2)"
1638
- @nendo.evalStr( " (apply list (list 1 '())) " ).should == "(1 ())"
1639
- @nendo.evalStr( " (apply list (list 1 (cdr '(100)))) " ).should == "(1 ())"
1640
- @nendo.evalStr( " (map (lambda (x) 1) '()) " ).should == "()"
1641
- @nendo.evalStr( " (map (lambda (x) 1) (to-list '#())) " ).should == "()"
1642
- @nendo.evalStr( " (map (lambda (x) (* x 2)) '(1 2 3)) " ).should == "(2 4 6)"
1643
- @nendo.evalStr( " (map (lambda (x) (+ x 1)) '(1 2 3)) " ).should == "(2 3 4)"
1644
- @nendo.evalStr( <<EOS
1645
- (map
1646
- (lambda (a b) (+ a b))
1647
- '(1 2 3)
1648
- '(10 20 30))
1649
- EOS
1650
- ).should == "(11 22 33)"
1651
- @nendo.evalStr( <<EOS
1652
- (map
1653
- (lambda (a b)
1654
- (- b a))
1655
- '(1 2 3)
1656
- '(10 20 30))
1657
- EOS
1658
- ).should == "(9 18 27)"
1659
- @nendo.evalStr( <<EOS
1660
- (map
1661
- (lambda (a b c)
1662
- (+ a b c))
1663
- '(1 2 3)
1664
- '(10 20 30)
1665
- '(100 200 300))
1666
- EOS
1667
- ).should == "(111 222 333)"
1668
- @nendo.evalStr( <<EOS
1669
- (define _result
1670
- (map
1671
- (lambda (x)
1672
- (* x 2))
1673
- (range 10000 1)))
1674
- (list
1675
- (first _result)
1676
- (second _result)
1677
- (last-pair _result))
1678
- EOS
1679
- ).should == "(2 4 (20000))"
1680
-
1681
- @nendo.evalStr( <<EOS
1682
- (list
1683
- (list* 1)
1684
- (list* 1 2)
1685
- (list* 1 2 3)
1686
- (list* 1 2 3 4))
1687
- EOS
1688
- ).should == "(1 (1 . 2) (1 2 . 3) (1 2 3 . 4))"
1689
-
1690
- @nendo.evalStr( <<EOS
1691
- (list
1692
- (list* '())
1693
- (list* 1 '())
1694
- (list* 1 2 '())
1695
- (list* 1 2 3 '()))
1696
- EOS
1697
- ).should == "(() (1) (1 2) (1 2 3))"
1698
-
1699
- @nendo.evalStr( <<EOS
1700
- (list
1701
- (list* (cdr '(100)))
1702
- (list* 1 (cdr '(100)))
1703
- (list* 1 2 (cdr '(100)))
1704
- (list* 1 2 3 (cdr '(100))))
1705
- EOS
1706
- ).should == "(() (1) (1 2) (1 2 3))"
1707
-
1708
- @nendo.evalStr( <<EOS
1709
- (list
1710
- (list* '())
1711
- (list* '() '())
1712
- (list* '() '() '())
1713
- (list* '() '() '() '()))
1714
- EOS
1715
- ).should == "(() (()) (() ()) (() () ()))"
1716
-
1717
- @nendo.evalStr( <<EOS
1718
- (define _lst '())
1719
- (for-each
1720
- (lambda (x)
1721
- (set! _lst (cons 1 _lst)))
1722
- '())
1723
- _lst
1724
- EOS
1725
- ).should == "()"
1726
- @nendo.evalStr( <<EOS
1727
- (define _lst '())
1728
- (for-each
1729
- (lambda (x)
1730
- (set! _lst (cons (* x 2) _lst)))
1731
- '(1 2 3))
1732
- _lst
1733
- EOS
1734
- ).should == "(6 4 2)"
1735
- @nendo.evalStr( <<EOS
1736
- (define _lst '())
1737
- (for-each
1738
- (lambda (x)
1739
- (set! _lst (cons (+ x 1) _lst)))
1740
- '(1 2 3))
1741
- _lst
1742
- EOS
1743
- ).should == "(4 3 2)"
1744
- @nendo.evalStr( <<EOS
1745
- (define _lst '())
1746
- (for-each
1747
- (lambda (a b)
1748
- (set! _lst (cons (cons a b) _lst)))
1749
- '(1 2 3)
1750
- '(10 20 30))
1751
- _lst
1752
- EOS
1753
- ).should ==
1754
- "((3 . 30) (2 . 20) (1 . 10))"
1755
- @nendo.evalStr( <<EOS
1756
- (define _cnt 0)
1757
- (for-each
1758
- (lambda (x)
1759
- (set! _cnt (+ _cnt 1)))
1760
- (range 10000))
1761
- _cnt
1762
- EOS
1763
- ).should == "10000"
1764
- @nendo.evalStr( " (filter (lambda (x) x) '()) " ).should == "()"
1765
- @nendo.evalStr( " (filter (lambda (x) (= x 100)) '(1 2 3)) " ).should == "()"
1766
- @nendo.evalStr( " (filter (lambda (x) (= x 2)) '(1 2 3)) " ).should == "(2)"
1767
- @nendo.evalStr( " (filter (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "(1 3)"
1768
- @nendo.evalStr( " (filter (lambda (x) (if (= x 2) (* x 100) false)) '(1 2 3)) " ).should == "(2)"
1769
- @nendo.evalStr( " (find (lambda (x) (= x 100)) '(1 2 3)) " ).should == "#f"
1770
- @nendo.evalStr( " (find (lambda (x) (= x 2)) '(1 2 3)) " ).should == "2"
1771
- @nendo.evalStr( " (find (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "1"
1772
- @nendo.evalStr( " (find (lambda (x) (if (= x 2) (* x 100) false)) '(1 2 3)) " ).should == "2"
1773
- @nendo.evalStr( " (eq? find any)" ).should == "#f"
1774
- @nendo.evalStr( " (find even? '(1 2 3)) " ).should == "2"
1775
- @nendo.evalStr( " (filter-map (lambda (x) x) '()) " ).should == "()"
1776
- @nendo.evalStr( " (filter-map (lambda (x) (= x 100)) '(1 2 3)) " ).should == "()"
1777
- @nendo.evalStr( " (filter-map (lambda (x) (= x 2)) '(1 2 3)) " ).should == "(#t)"
1778
- @nendo.evalStr( " (filter-map (lambda (x) (not (= x 2))) '(1 2 3)) " ).should == "(#t #t)"
1779
- @nendo.evalStr( " (fold (lambda (x y) x y) 0 '()) " ).should == "0"
1780
- @nendo.evalStr( " (fold (lambda (x y) (+ x y)) 0 '(1 2 3)) " ).should == "6"
1781
- @nendo.evalStr( " (fold (lambda (x y) (+ x y)) 1 '(2 3 4)) " ).should == "10"
1782
- @nendo.evalStr( " (fold (lambda (x y) (* x y)) 1 '(2 3 4 5)) " ).should == "120"
1783
- @nendo.evalStr( " (fold (lambda (x y) (* x y)) 0 '(2 3 4 5)) " ).should == "0"
1784
- @nendo.evalStr( <<EOS
1785
- (filter-map
1786
- (lambda (x)
1787
- (if (= x 2) (* x 10) false))
1788
- '(1 2 3))
1789
- EOS
1790
- ).should == "(20)"
1791
- @nendo.evalStr( <<EOS
1792
- (filter-map
1793
- (lambda (x)
1794
- (if (not (= x 2)) (* x 10) false))
1795
- '(1 2 3))
1796
- EOS
1797
- ).should == "(10 30)"
1798
- @nendo.evalStr( " (any even? '(1 2 3)) " ).should == "#t"
1799
- @nendo.evalStr( " (any even? '(1 3)) " ).should == "#f"
1800
- @nendo.evalStr( " (any odd? '(1 3)) " ).should == "#t"
1801
- @nendo.evalStr( " (any (lambda (x) x) '(1 2 3)) " ).should == "1"
1802
- @nendo.evalStr( <<EOS
1803
- (let1 result '()
1804
- (do
1805
- ((i 0 (+ i 1)))
1806
- ((< 10 i) #f)
1807
- (set! result (cons i result)))
1808
- (reverse result))
1809
- EOS
1810
- ).should == "(0 1 2 3 4 5 6 7 8 9 10)"
1811
- @nendo.evalStr( <<EOS
1812
- (let1 result '()
1813
- (do
1814
- ((i 0 (+ i 3)))
1815
- ((< (* 3 10) i) #f)
1816
- (set! result (cons i result)))
1817
- (reverse result))
1818
- EOS
1819
- ).should == "(0 3 6 9 12 15 18 21 24 27 30)"
1820
- end
1821
- end
1822
-
1823
- describe Nendo, "when use raise function " do
1824
- before do
1825
- @nendo = Nendo::Core.new()
1826
- @nendo.setDisplayErrors( false )
1827
- @nendo.loadInitFile
1828
- end
1829
- it "should" do
1830
- lambda { @nendo.evalStr( ' (%raise TypeError "typeError" "nendo_spec.rb:1 typeError" ) ' ) }.should raise_error( TypeError )
1831
- lambda { @nendo.evalStr( ' (%raise ArgumentError "argumentError" "nendo_spec.rb:1 argumentError") ' ) }.should raise_error( ArgumentError )
1832
- lambda { @nendo.evalStr( ' (raise TypeError "typeError" ) ' ) }.should raise_error( TypeError )
1833
- lambda { @nendo.evalStr( ' (raise ArgumentError "argumentError" ) ' ) }.should raise_error( ArgumentError )
1834
- lambda { @nendo.evalStr( ' (raise TypeError ) ' ) }.should raise_error( TypeError )
1835
- lambda { @nendo.evalStr( ' (raise ArgumentError ) ' ) }.should raise_error( ArgumentError )
1836
- end
1837
- end
1838
-
1839
- describe Nendo, "when use values " do
1840
- before do
1841
- @nendo = Nendo::Core.new()
1842
- @nendo.setDisplayErrors( false )
1843
- @nendo.loadInitFile
1844
- end
1845
- it "should" do
1846
- @nendo.evalStr( " (values? (make-values '())) " ).should == "#t"
1847
- lambda { @nendo.evalStr( " (make-values '(1))) " ) }.should raise_error(ArgumentError)
1848
- @nendo.evalStr( " (values? (make-values '(1 2))) " ).should == "#t"
1849
- @nendo.evalStr( " (values? (make-values '(1 2 3))) " ).should == "#t"
1850
- @nendo.evalStr( " (values? (values)) " ).should == "#t"
1851
- @nendo.evalStr( " (values? (values 1)) " ).should == "#f"
1852
- @nendo.evalStr( " (values 1) " ).should == "1"
1853
- @nendo.evalStr( " (values? (values 1 2)) " ).should == "#t"
1854
- @nendo.evalStr( " (values? (values 1 2 3)) " ).should == "#t"
1855
- @nendo.evalStr( " (values? (values '(a) \"b\" '(\"C\"))) " ).should == "#t"
1856
- @nendo.evalStr( " (values-values (values)) " ).should == "()"
1857
- lambda { @nendo.evalStr( " (values-values (values 1)) " ) }.should raise_error(TypeError)
1858
- @nendo.evalStr( " (values-values (values 1 2)) " ).should == "(1 2)"
1859
- @nendo.evalStr( " (values-values (values 1 2 3)) " ).should == "(1 2 3)"
1860
- @nendo.evalStr( " (values-values (values '(a) \"b\" '(\"C\"))) " ).should == '((a) "b" ("C"))'
1861
- @nendo.evalStr( <<EOS
1862
- (call-with-values
1863
- (lambda () (values 4 5))
1864
- (lambda (a b) b))
1865
- EOS
1866
- ).should == "5"
1867
- @nendo.evalStr( <<EOS
1868
- (call-with-values
1869
- (lambda () (values 1 2))
1870
- cons)
1871
- EOS
1872
- ).should == "(1 . 2)"
1873
- @nendo.evalStr( <<EOS
1874
- (call-with-values
1875
- (lambda () (values 10))
1876
- list)
1877
- EOS
1878
- ).should == "(10)"
1879
- @nendo.evalStr( <<EOS
1880
- (call-with-values
1881
- (lambda () (values))
1882
- list)
1883
- EOS
1884
- ).should == "()"
1885
- @nendo.evalStr( " (call-with-values * -) " ).should == "-1"
1886
- @nendo.evalStr( " (receive (a) (values 10) (list a)) " ).should == "(10)"
1887
- @nendo.evalStr( " (receive (a b) (values 10 20) (list a b)) " ).should == "(10 20)"
1888
- @nendo.evalStr( " (receive (a b c) (values 10 20 30) (list a b c)) " ).should == "(10 20 30)"
1889
- @nendo.evalStr( " (receive (a . b) (values 10) (list a b)) " ).should == "(10 ())"
1890
- @nendo.evalStr( " (receive (a . b) (values 10 20) (list a b)) " ).should == "(10 (20))"
1891
- @nendo.evalStr( " (receive (a . b) (values 10 20 30) (list a b)) " ).should == "(10 (20 30))"
1892
- @nendo.evalStr( " (receive all (values) all) " ).should == "()"
1893
- @nendo.evalStr( " (receive all (values 10) all) " ).should == "(10)"
1894
- @nendo.evalStr( " (receive all (values 10 20) all) " ).should == "(10 20)"
1895
- @nendo.evalStr( " (receive all (values 10 20 30) all) " ).should == "(10 20 30)"
1896
- @nendo.evalStr( " (receive (a b) (values '(1) '(2)) (list a b)) " ).should == "((1) (2))"
1897
- @nendo.evalStr( " (receive (a b) (values '() '(2)) (list a b)) " ).should == "(() (2))"
1898
- @nendo.evalStr( " (receive (a b) (values '(1) '()) (list a b)) " ).should == "((1) ())"
1899
- @nendo.evalStr( " (receive (a b) (values #t #t) (cons a b)) " ).should == "(#t . #t)"
1900
- @nendo.evalStr( " (receive (a b) (values #t #f) (cons a b)) " ).should == "(#t . #f)"
1901
- @nendo.evalStr( " (receive (a b) (values nil #t) (cons a b)) " ).should == "(nil . #t)"
1902
- @nendo.evalStr( " (receive (a b) (values nil #f) (cons a b)) " ).should == "(nil . #f)"
1903
- @nendo.evalStr( " (receive (a b) (values nil nil) (cons a b)) " ).should == "(nil . nil)"
1904
- lambda { @nendo.evalStr( " (receive (a) (values) (list a)) " ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
1905
- lambda { @nendo.evalStr( <<EOS
1906
- (map
1907
- (lambda (a) a))
1908
- EOS
1909
- ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
1910
- lambda { @nendo.evalStr( <<EOS
1911
- (map
1912
- (lambda () 1)
1913
- '(1 2 3))
1914
- EOS
1915
- ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
1916
- lambda { @nendo.evalStr( <<EOS
1917
- (map
1918
- (lambda (a) a)
1919
- '(1 2 3)
1920
- '(10 20 30))
1921
- EOS
1922
- ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
1923
- lambda { @nendo.evalStr( <<EOS
1924
- (map
1925
- (lambda (a b) (+ a b))
1926
- '(1 2 3))
1927
- EOS
1928
- ) }.should raise_error( ArgumentError, /wrong number of arguments/ )
1929
- end
1930
- end
1931
-
1932
- describe Nendo, "when toplevel variable was overwritten " do
1933
- before do
1934
- @nendo = Nendo::Core.new()
1935
- @nendo.setDisplayErrors( false )
1936
- @nendo.loadInitFile
1937
- end
1938
- it "should" do
1939
- @nendo.evalStr( " (define a 1) a" ).should == "1"
1940
- lambda { @nendo.evalStr( " (define (c-func) (+ a b)) (c-func)" ) }.should raise_error( NameError )
1941
- @nendo.evalStr( " (define b 2) b" ).should == "2"
1942
- @nendo.evalStr( " (c-func) " ).should == "3"
1943
- @nendo.evalStr( " (define b 20) " ).should == "20"
1944
- @nendo.evalStr( " (c-func) " ).should == "21"
1945
-
1946
- @nendo.evalStr( " (define (a-func) 10) (a-func)" ).should == "10"
1947
- lambda { @nendo.evalStr( " (define (c-func) (* (a-func) (b-func))) (c-func)" ) }.should raise_error( NameError )
1948
- @nendo.evalStr( " (define (b-func) 20) (b-func)" ).should == "20"
1949
- @nendo.evalStr( " (c-func) " ).should == "200"
1950
- @nendo.evalStr( " (define (b-func) 200) (b-func)" ).should == "200"
1951
- @nendo.evalStr( " (c-func) " ).should == "2000"
1952
- end
1953
- end
1954
-
1955
- describe Nendo, "when use quasiquote macro " do
1956
- before do
1957
- @nendo = Nendo::Core.new()
1958
- @nendo.loadInitFile
1959
- end
1960
- it "should" do
1961
- @nendo.evalStr( " '(a b c) " ).should == "(a b c)"
1962
- @nendo.evalStr( " `(a b c) " ).should == "(a b c)"
1963
- @nendo.evalStr( " `(1 2 3) " ).should == "(1 2 3)"
1964
- @nendo.evalStr( " (set! a 3) `(1 2 ,a) " ).should == "(1 2 3)"
1965
- @nendo.evalStr( " (set! a 3) `(1 2 ,@(list a)) " ).should == "(1 2 3)"
1966
- @nendo.evalStr( " (set! a 3) `(1 ,@(list 2 a)) " ).should == "(1 2 3)"
1967
- @nendo.evalStr( " (set! a 11) `,a " ).should == "11"
1968
- @nendo.evalStr( " (set! a 12) ``,a " ).should == "(quasiquote (unquote a))"
1969
- @nendo.evalStr( ' (define str "string") str ' ).should == '"string"'
1970
- @nendo.evalStr( ' `(,str) ' ).should == '("string")'
1971
- @nendo.evalStr( ' `("STRING") ' ).should == '("STRING")'
1972
- @nendo.evalStr( ' `(,str "STRING") ' ).should == '("string" "STRING")'
1973
- @nendo.evalStr( ' `("STRING" ,str) ' ).should == '("STRING" "string")'
1974
- @nendo.evalStr( ' (car `("STRING" ,str)) ' ).should == '"STRING"'
1975
- @nendo.evalStr( ' (second `("STRING" ,str)) ' ).should == '"string"'
1976
- @nendo.evalStr( ' (caar `(("STRING" ,str))) ' ).should == '"STRING"'
1977
- @nendo.evalStr( ' (string-join `("A" "B" "C" "D")) ' ).should == '"ABCD"'
1978
- @nendo.evalStr( " `(list ,(+ 1 2) 4) " ).should == "(list 3 4)"
1979
- @nendo.evalStr( " (let ((name 'a)) `(list ,name ',name)) " ).should == "(list a (quote a))"
1980
- @nendo.evalStr( " `(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f) " ).should == "(a (quasiquote (b (unquote (+ 1 2)) (unquote (foo 4 d)) e)) f)"
1981
- @nendo.evalStr( " `(( foo ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons))) " ).should == "((foo 7) . cons)"
1982
- end
1983
- end
1984
-
1985
- describe Nendo, "when use macros made by quasiquote. " do
1986
- before do
1987
- @nendo = Nendo::Core.new()
1988
- @nendo.loadInitFile
1989
- end
1990
- it "should" do
1991
- @nendo.evalStr( " (case (length '(1 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"one"'
1992
- @nendo.evalStr( " (case (length '(1 2 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"two"'
1993
- @nendo.evalStr( " (case (length '(1 2 3 )) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1994
- @nendo.evalStr( " (case (length '(1 2 3 4)) ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1995
- @nendo.evalStr( " (case 100 ((1) \"one\") ((2) \"two\") (else \"else\")) " ).should == '"else"'
1996
- @nendo.evalStr( " (case (car '(a b 1)) ((a) 'a) ((b) 'b) (else 'else)) " ).should == 'a'
1997
- @nendo.evalStr( " (case (cadr '(a b 1)) ((a) 'a) ((b) 'b) (else 'else)) " ).should == 'b'
1998
- @nendo.evalStr( " (case (caddr '(a b 1)) ((a b) 'a) ((1 2) 'number) (else 'else)) " ).should == 'number'
1999
- @nendo.evalStr( " (case (cadddr '(a b 1 2)) ((a b) 'a) ((1 2) 'number) (else 'else)) " ).should == 'number'
2000
- @nendo.evalStr( " (let* ((a 1) (b (+ a 2))) (cons a b)) " ).should == "(1 . 3)"
2001
- @nendo.evalStr( " (let* ((a 10) (b (* a 2))) (cons a b)) " ).should == "(10 . 20)"
2002
- @nendo.evalStr( " (let* ((a 10) (b (* a 2)) (c (* b 3))) (list a b c)) " ).should == "(10 20 60)"
2003
- @nendo.evalStr( " (begin0 1 2 3) " ).should == "1"
2004
- @nendo.evalStr( <<EOS
2005
- (define a 2)
2006
- (begin0 (set! a (* a 2))
2007
- (set! a (* a 2))
2008
- (set! a (* a 2)))
2009
- EOS
2010
- ).should == "4"
2011
- @nendo.evalStr( " (begin0 100) " ).should == "100"
2012
- @nendo.evalStr( " (begin0) " ).should == "#f"
2013
- @nendo.evalStr( <<EOS
2014
- (receive (a b)
2015
- (begin0
2016
- (values 1 2)
2017
- (values 10 20)
2018
- (values 100 200))
2019
- (cons a b))
2020
- EOS
2021
- ).should == "(1 . 2)"
2022
- @nendo.evalStr( " (macroexpand '(when #t (print \"1\") (print \"2\"))) " ).should == '(if #t (begin (print "1") (print "2")))'
2023
- @nendo.evalStr( " (macroexpand '(unless #t (print \"1\") (print \"2\"))) " ).should == '(if (not #t) (begin (print "1") (print "2")))'
2024
- @nendo.evalStr( " (macroexpand '(if-let1 a #t (print \"T\") (print \"F\"))) " ).should == '(%let ((a #t)) (if a (print "T") (print "F")))'
2025
- @nendo.evalStr( " (let1 count 0 (when #t (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "2"
2026
- @nendo.evalStr( " (let1 count 0 (when #f (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "0"
2027
- @nendo.evalStr( " (let1 count 0 (unless #t (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "0"
2028
- @nendo.evalStr( " (let1 count 0 (unless #f (set! count (+ count 1)) (set! count (+ count 1))) count) " ).should == "2"
2029
- @nendo.evalStr( " (if-let1 m (rxmatch #/([0-9]+)/ \"abc100abc\") (rxmatch-substring m 1)) " ).should == '"100"'
2030
- @nendo.evalStr( " (macroexpand '#?.) " ).should == '"(string):1"'
2031
- @nendo.evalStr( " (macroexpand '(begin 1 2 #?. 4 5)) " ).should == '(begin 1 2 "(string):1" 4 5)'
2032
- end
2033
- end
2034
-
2035
- describe Nendo, "when use define and lambda macro " do
2036
- before do
2037
- @nendo = Nendo::Core.new()
2038
- @nendo.loadInitFile
2039
- end
2040
- it "should" do
2041
- @nendo.evalStr( <<EOS
2042
- (macroexpand
2043
- '(define (main argv)
2044
- (newline)
2045
- 0))
2046
- EOS
2047
- ).should == "(define main (lambda (argv) (newline) 0))"
2048
- @nendo.evalStr( <<EOS
2049
- (macroexpand
2050
- '(define (main argv)
2051
- (define (foo x) x)
2052
- (+ 10 20)
2053
- 0
2054
- (foo 111)))
2055
- EOS
2056
- ).should == "(define main (lambda (argv) (letrec ((foo (lambda (x) x))) (+ 10 20) 0 (foo 111))))"
2057
- @nendo.evalStr( <<EOS
2058
- (macroexpand
2059
- '(define (main argv)
2060
- (define result '())
2061
- (define (foo x) x)
2062
- (define val 0)
2063
- (define (bar x)
2064
- (+ val 10))))
2065
- EOS
2066
- ).should == "(define main (lambda (argv) (letrec ((result (quote ())) (foo (lambda (x) x)) (val 0) (bar (lambda (x) (+ val 10)))))))"
2067
- @nendo.evalStr( <<EOS
2068
- (define (main . argv)
2069
- (define (foo x) x)
2070
- (+ 10 20)
2071
- 0
2072
- (foo 111))
2073
- (main)
2074
- EOS
2075
- ).should == "111"
2076
- @nendo.evalStr( <<EOS
2077
- (define (main argv)
2078
- (define (foo1 x) (+ 1 x))
2079
- (define (foo2 x) (+ 2 x))
2080
- (*
2081
- (foo1 20)
2082
- (foo2 30)))
2083
- (main '())
2084
- EOS
2085
- ).should == "672"
2086
- @nendo.evalStr( " (macroexpand '(define (main argv) 0)) " ).should == "(define main (lambda (argv) 0))"
2087
- end
2088
- end
2089
-
2090
- describe Nendo, "when use macro macro " do
2091
- before do
2092
- @nendo = Nendo::Core.new()
2093
- @nendo.loadInitFile
2094
- end
2095
- it "should" do
2096
- @nendo.evalStr( <<EOS
2097
- (define inc!-macro
2098
- (macro (x)
2099
- (+ x 1)))
2100
- EOS
2101
- ).should match( /Nendo::LispMacro/ )
2102
- @nendo.evalStr( " (inc!-macro 10) " ).should == "11"
2103
- @nendo.evalStr( <<EOS
2104
- (define dec!-macro
2105
- (macro (x)
2106
- (define (dec! v)
2107
- (- v 1))
2108
- (dec! x)))
2109
- EOS
2110
- ).should match( /Nendo::LispMacro/ )
2111
- @nendo.evalStr( " (dec!-macro 10) " ).should == "9"
2112
- @nendo.evalStr( " (. (dec!-macro 10) class) " ).should == 'Fixnum'
2113
- end
2114
- end
2115
-
2116
- describe Nendo, "when use macros expand some syntax. " do
2117
- before do
2118
- @nendo = Nendo::Core.new()
2119
- @nendo.loadInitFile
2120
- end
2121
- it "should" do
2122
- @nendo.evalStr( "" +
2123
- " (let1 total 0" +
2124
- " (let loop ((cnt 10))" +
2125
- " (if (< 0 cnt)" +
2126
- " (begin" +
2127
- " (set! total (+ total cnt))" +
2128
- " (loop (- cnt 1)))))" +
2129
- " total)" +
2130
- "" ).should == "55"
2131
- @nendo.evalStr( "" +
2132
- "(let label ((a 2)" +
2133
- " (b 3))" +
2134
- " (if (<= 9 (+ a b))" +
2135
- " (* a b)" +
2136
- " (label 4 5)))" +
2137
- "" ).should == "20"
2138
- @nendo.evalStr( "" +
2139
- "(macroexpand '(let loop ((x 1)) "+
2140
- " 1"+
2141
- " 2"+
2142
- " (loop 100)))" ).should == "(letrec ((loop (lambda (x) 1 2 (loop 100)))) (loop 1))"
2143
- end
2144
- end
2145
-
2146
- describe Nendo, "when occur illegal syntax. " do
2147
- before do
2148
- @nendo = Nendo::Core.new()
2149
- @nendo.loadInitFile
2150
- end
2151
- it "should" do
2152
-
2153
- lambda { @nendo.evalStr( <<EOS
2154
- (let abc 1 ;; let1 style form is illegal syntax for let form.
2155
- (print abc))
2156
- EOS
2157
- ) }.should raise_error( SyntaxError, /^named let requires/ )
2158
-
2159
- lambda { @nendo.evalStr( "(let 1)" ) }.should raise_error( SyntaxError, /^let requires/ )
2160
- lambda { @nendo.evalStr( "(let ())" ) }.should raise_error( SyntaxError, /^let requires/ )
2161
- @nendo.evalStr( "(let () 1)" ).should == '1'
2162
- lambda { @nendo.evalStr( "(let loop 1)" ) }.should raise_error( SyntaxError, /^named let requires/ )
2163
- lambda { @nendo.evalStr( "(let loop ())" ) }.should raise_error( SyntaxError, /^named let requires/ )
2164
- @nendo.evalStr( "(let loop () 1)" ).should == '1'
2165
-
2166
- lambda { @nendo.evalStr( "(let1)" ) }.should raise_error( SyntaxError, /^let1 requires/ )
2167
- lambda { @nendo.evalStr( "(let1 a)" ) }.should raise_error( SyntaxError, /^let1 requires/ )
2168
- lambda { @nendo.evalStr( "(let1 a 1)" ) }.should raise_error( SyntaxError, /^let1 requires/ )
2169
- lambda { @nendo.evalStr( "(let1 (a 1) (print a))" ) }.should raise_error( SyntaxError, /^let1 requires/ )
2170
- lambda { @nendo.evalStr( "(let1 ((a 1)) (print a))" ) }.should raise_error( SyntaxError, /^let1 requires/ )
2171
- @nendo.evalStr( "(let1 a 123 a)" ).should == '123'
2172
- @nendo.evalStr( "(let1 b (+ 100 20 3) b)" ).should == '123'
2173
- end
2174
- end
2175
-
2176
-
2177
- describe Nendo, "when use dot-operator (.) macro " do
2178
- before do
2179
- @nendo = Nendo::Core.new()
2180
- @nendo.setDisplayErrors( false )
2181
- @nendo.loadInitFile
2182
- end
2183
- it "should" do
2184
- @nendo.evalStr( " (macroexpand '(. a b)) " ).should == "(a.b)"
2185
- @nendo.evalStr( " (macroexpand '(. a b c)) " ).should == "(a.b c)"
2186
- @nendo.evalStr( " (macroexpand '(. Kernel open)) " ).should == "(Kernel.open)"
2187
- lambda { @nendo.evalStr( " (macroexpand '(. open)) " ) }.should raise_error( ArgumentError )
2188
- lambda { @nendo.evalStr( " (macroexpand '(. open \"aaa\")) " ) }.should raise_error( TypeError )
2189
- @nendo.evalStr( " (macroexpand '(. a size)) " ).should == "(a.size)"
2190
- @nendo.evalStr( " (macroexpand '(. (. a size) to_s)) " ).gsub( /_[0-9][0-9][0-9][0-9][0-9]/, "_X0000" ).should == "(%let ((__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000 (a.size))) (__gensym__fb4e25e49e9fb4e46342224606faf2e3eabf1251_X0000.to_s))"
2191
- @nendo.evalStr( " (macroexpand '(. (. (. a size) to_s) to_i)) " ).gsub( /_[0-9][0-9][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))"
2192
- lambda { @nendo.evalStr( " (macroexpand '(. (. a size))) " ) }.should raise_error( ArgumentError )
2193
- @nendo.evalStr( " (set! str \"str\") str.size " ).should == "3"
2194
- @nendo.evalStr( " (set! str \"str\") (. str size) " ).should == "3"
2195
- @nendo.evalStr( " (set! str \"str\") (+ 1 (. str size)) " ).should == "4"
2196
- @nendo.evalStr( " (set! str \"string\") (. (. str size) to_s) " ).should == '"6"'
2197
- @nendo.evalStr( " (to-s str.size) " ).should == '"6"'
2198
- @nendo.evalStr( " (to-s 'str.size) " ).should == '"str.size"'
2199
- @nendo.evalStr( " (require \"date\") " ).should == "#f"
2200
- @nendo.evalStr( " (. (Date.new 0) strftime \"%F %r\") " ).should == '"0000-01-01 12:00:00 AM"'
2201
- @nendo.evalStr( " (require \"digest/md5\") " ).should == "#f"
2202
- @nendo.evalStr( " (Digest::MD5.hexdigest \"abc\") " ).should == '"900150983cd24fb0d6963f7d28e17f72"'
2203
- @nendo.evalStr( " (Digest::MD5.hexdigest \"source text\") " ).should == '"20f79a1416626eeacc0bd9a8db87faa2"'
2204
- @nendo.evalStr( " (define a 1) (a.is_a? Fixnum) " ).should == "#t"
2205
- @nendo.evalStr( " (define a 1) (a.is_a? Float) " ).should == "#f"
2206
- @nendo.evalStr( " (define a 1) (a.is_a? String) " ).should == "#f"
2207
- @nendo.evalStr( " (define a 1.1) (a.is_a? Fixnum) " ).should == "#f"
2208
- @nendo.evalStr( " (define a 1.1) (a.is_a? Float) " ).should == "#t"
2209
- @nendo.evalStr( " (define a 1.1) (a.is_a? String) " ).should == "#f"
2210
- @nendo.evalStr( " (define a \"s\") (a.is_a? Fixnum) " ).should == "#f"
2211
- @nendo.evalStr( " (define a \"s\") (a.is_a? Float) " ).should == "#f"
2212
- @nendo.evalStr( " (define a \"s\") (a.is_a? String) " ).should == "#t"
2213
- @nendo.evalStr( ' (equal? (read-from-string "\"100\"") (. 100 to_s)) ' ).should == "#t"
2214
- end
2215
- end
2216
-
2217
- describe Nendo, "when use dot-operator (.) macro and (&block ...) " do
2218
- before do
2219
- @nendo = Nendo::Core.new()
2220
- @nendo.loadInitFile
2221
- end
2222
- it "should" do
2223
- @nendo.evalStr( " (define arr '#(10 50 40 10000 20 30))" ).should == "#(10 50 40 10000 20 30)"
2224
- @nendo.evalStr( " (arr.sort)" ).should == "#(10 20 30 40 50 10000)"
2225
- @nendo.evalStr( " (arr.sort (&block (a b) (if (le? a b) 1 -1))) " ).should == "#(10000 50 40 30 20 10)"
2226
- @nendo.evalStr( " (arr.sort_by (&block (item) item.to_s)) " ).should == "#(10 10000 20 30 40 50)"
2227
- end
2228
- end
2229
-
2230
- describe Nendo, "when use sort libraries " do
2231
- before do
2232
- @nendo = Nendo::Core.new()
2233
- @nendo.loadInitFile
2234
- end
2235
- it "should" do
2236
- @nendo.evalStr( " (define lst '(1 50 60 30000 4000 200)) " ).should == "(1 50 60 30000 4000 200)"
2237
- @nendo.evalStr( " (sort lst) " ).should == "(1 50 60 200 4000 30000)"
2238
- @nendo.evalStr( " (sort '()) " ).should == "()"
2239
- @nendo.evalStr( " (sort lst (lambda (a b) (- b a))) " ).should == "(30000 4000 200 60 50 1)"
2240
- @nendo.evalStr( " (sort-by lst (lambda (item) item)) " ).should == "(1 50 60 200 4000 30000)"
2241
- @nendo.evalStr( " (sort-by '() (lambda (item) item)) " ).should == "()"
2242
- @nendo.evalStr( " (define lst2 '((1 . \"ddd\") (2 . \"cc\") (3 . \"bbbb\") (4 . \"a\"))) " ).should == '((1 . "ddd") (2 . "cc") (3 . "bbbb") (4 . "a"))'
2243
- @nendo.evalStr( " (sort lst2 (lambda (a b) (- (car a) (car b)))) " ).should == '((1 . "ddd") (2 . "cc") (3 . "bbbb") (4 . "a"))'
2244
- @nendo.evalStr( " (sort lst2 (lambda (a b) (if (>= (cdr a) (cdr b)) 1 -1))) " ).should == '((4 . "a") (3 . "bbbb") (2 . "cc") (1 . "ddd"))'
2245
- @nendo.evalStr( " (sort-by lst2 (lambda (item) (car item))) " ).should == '((1 . "ddd") (2 . "cc") (3 . "bbbb") (4 . "a"))'
2246
- @nendo.evalStr( " (sort-by lst2 (lambda (item) (cdr item))) " ).should == '((4 . "a") (3 . "bbbb") (2 . "cc") (1 . "ddd"))'
2247
- @nendo.evalStr( " (sort-by lst2 (lambda (item) (. (cdr item) size))) " ).should == '((4 . "a") (2 . "cc") (1 . "ddd") (3 . "bbbb"))'
2248
- end
2249
- end
2250
-
2251
- describe Nendo, "when use with-open libraries " do
2252
- before do
2253
- @nendo = Nendo::Core.new()
2254
- @nendo.setDisplayErrors( false )
2255
- @nendo.loadInitFile
2256
- @fn = "/tmp/for-with-open.dat"
2257
- open( @fn, "w" ) { |f|
2258
- f.puts( "line1" )
2259
- f.puts( "line2" )
2260
- f.puts( "line3" )
2261
- }
2262
- end
2263
- it "should" do
2264
- @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"line1"'
2265
- @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"line1"'
2266
- @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop) (f.readline.chop))) ", @fn )).should == '"line2"'
2267
- @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (map (lambda (line) (line.chop)) f))) ", @fn )).should == '#("line1" "line2" "line3")'
2268
- @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.puts \"Wrote from Nendo.\")) \"w\") #t", @fn )).should == "#t"
2269
- @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) (f.readline.chop))) ", @fn )).should == '"Wrote from Nendo."'
2270
- lambda { @nendo.evalStr( sprintf( " (with-open \"%s\" (lambda (f) #t) 1 2 ", @fn )) }.should raise_error(RuntimeError)
2271
- lambda { @nendo.evalStr( sprintf( " (with-open \"%s\" \"string\" 1 2 ", @fn )) }.should raise_error(RuntimeError)
2272
- end
2273
-
2274
- after do
2275
- File.unlink( @fn )
2276
- end
2277
- end
2278
-
2279
- describe Nendo, "when use (use ...) macro " do
2280
- before do
2281
- @nendo = Nendo::Core.new()
2282
- @nendo.setDisplayErrors( false )
2283
- @nendo.loadInitFile
2284
- end
2285
- it "should" do
2286
- @nendo.evalStr( " (macroexpand '(use abc)) " ).should == '(load "abc")'
2287
- @nendo.evalStr( " (macroexpand '(use a.b)) " ).should == '(load "a/b")'
2288
- @nendo.evalStr( " (macroexpand '(use a.b.c)) " ).should == '(load "a/b/c")'
2289
- @nendo.evalStr( " (macroexpand '(use a.b.c.d.e.f.g)) " ).should == '(load "a/b/c/d/e/f/g")'
2290
- @nendo.evalStr( " (macroexpand '(use srfi-1)) " ).should == '(load "srfi-1")'
2291
- @nendo.evalStr( " (macroexpand '(use text.tree)) " ).should == '(load "text/tree")'
2292
- @nendo.evalStr( " (macroexpand '(use debug.syslog)) " ).should == '(load "debug/syslog")'
2293
- @nendo.evalStr( " (macroexpand `(use ,(string->symbol (+ \"text\" \".\" \"tree\")))) " ).should == '(load "text/tree")'
2294
- lambda { @nendo.evalStr( " (macroexpand '(use '(a)) " ) }.should raise_error( RuntimeError )
2295
- lambda { @nendo.evalStr( " (macroexpand '(use \"srfi-1\") " ) }.should raise_error( RuntimeError )
2296
- lambda { @nendo.evalStr( " (macroexpand '(use 1)) " ) }.should raise_error( RuntimeError )
2297
- lambda { @nendo.evalStr( " (macroexpand '(use (+ 10 20))) " ) }.should raise_error( RuntimeError )
2298
- end
2299
- end
2300
-
2301
- describe Nendo, "when use keyword feature " do
2302
- before do
2303
- @nendo = Nendo::Core.new()
2304
- @nendo.setDisplayErrors( false )
2305
- @nendo.loadInitFile
2306
- end
2307
- it "should" do
2308
- @nendo.evalStr( " (keyword? :a) " ).should == "#t"
2309
- @nendo.evalStr( ' (keyword? (intern ":a")) ' ).should == "#f"
2310
- @nendo.evalStr( ' (symbol? (intern ":a")) ' ).should == "#t"
2311
- @nendo.evalStr( " (keyword? ':a) " ).should == "#t"
2312
- @nendo.evalStr( " (symbol? ':a) " ).should == "#f"
2313
- @nendo.evalStr( " (eq? :a :a) " ).should == "#t"
2314
- @nendo.evalStr( " (eqv? :a :a) " ).should == "#t"
2315
- @nendo.evalStr( ' (eq? :a (intern ":a")) ' ).should == "#f"
2316
- @nendo.evalStr( ' (eqv? :a (intern ":a")) ' ).should == "#f"
2317
- @nendo.evalStr( ' (keyword? (make-keyword "a")) ' ).should == "#t"
2318
- @nendo.evalStr( " :a " ).should == ":a"
2319
- @nendo.evalStr( " ::a " ).should == "::a"
2320
- @nendo.evalStr( " :::key " ).should == ":::key"
2321
- @nendo.evalStr( ' (make-keyword "a") ' ).should == ":a"
2322
- @nendo.evalStr( ' (make-keyword ":a") ' ).should == "::a"
2323
- @nendo.evalStr( " (make-keyword 'a) " ).should == ":a"
2324
- @nendo.evalStr( " (keyword->string :a) " ).should == '"a"'
2325
- @nendo.evalStr( " (keyword->string :abcde) " ).should == '"abcde"'
2326
- lambda { @nendo.evalStr( " (keyword->string 'a) " ) }.should raise_error( TypeError )
2327
- @nendo.evalStr( " : " ).should == ':'
2328
- @nendo.evalStr( " (keyword->string :) " ).should == '""'
2329
- @nendo.evalStr( ' (make-keyword "") ' ).should == ":"
2330
- @nendo.evalStr( " (get-keyword :y '(:x 1 :y 2 :z 3)) " ).should == "2"
2331
- @nendo.evalStr( " (get-keyword 'z '(x 1 y 2 z 3)) " ).should == "3"
2332
- lambda { @nendo.evalStr( " (get-keyword 'z '(x 1 y 2 z)) " ) }.should raise_error( RuntimeError )
2333
- lambda { @nendo.evalStr( " (get-keyword :t '(:x 1 :y 2 :z 3)) " ) }.should raise_error( RuntimeError )
2334
- @nendo.evalStr( " (get-keyword :t '() #f) " ).should == "#f"
2335
- @nendo.evalStr( " (get-keyword :t '(:x) #f) " ).should == "#f"
2336
- lambda { @nendo.evalStr( " (get-keyword :t '()) " ) }.should raise_error( RuntimeError )
2337
- lambda { @nendo.evalStr( " (get-keyword :t '(:x)) " ) }.should raise_error( RuntimeError )
2338
- lambda { @nendo.evalStr( " (get-keyword :t 1) " ) }.should raise_error( RuntimeError )
2339
- @nendo.evalStr( " (get-keyword :t 1 #f) " ).should == "#f"
2340
- end
2341
- end
2342
-
2343
- describe Nendo, "when use hash-table feature " do
2344
- before do
2345
- @nendo = Nendo::Core.new()
2346
- @nendo.setDisplayErrors( false )
2347
- @nendo.loadInitFile
2348
- end
2349
- it "should" do
2350
- @nendo.evalStr( " (define h (make-hash-table)) " ).should == "{}"
2351
- @nendo.evalStr( " (hash-table? 1) " ).should == "#f"
2352
- @nendo.evalStr( " (hash-table? '(1)) " ).should == "#f"
2353
- @nendo.evalStr( " (hash-table? (Array.new)) " ).should == "#f"
2354
- @nendo.evalStr( " (hash-table? (Hash.new)) " ).should == "#t"
2355
- @nendo.evalStr( " h " ).should == "{}"
2356
- @nendo.evalStr( " (hash-table-put! h 'k1 'v1) h" ).should == "{:k1=>:v1}"
2357
- @nendo.evalStr( " (hash-table-put! h 'k2 200) h" ).should == "{:k1=>:v1, :k2=>200}"
2358
- @nendo.evalStr( " (hash-table-get h 'k1)" ).should == "v1"
2359
- @nendo.evalStr( " (hash-table-get h 'k2)" ).should == "200"
2360
- @nendo.evalStr( " (hash-table-exist? h 'k1)" ).should == "#t"
2361
- @nendo.evalStr( " (hash-table-exist? h 'k2)" ).should == "#t"
2362
- @nendo.evalStr( " (hash-table-exist? h 'k3)" ).should == "#f"
2363
- @nendo.evalStr( " (hash-table-exist? h \"k1\")" ).should == "#f"
2364
- @nendo.evalStr( " (hash-table-num-entries h)" ).should == "2"
2365
- @nendo.evalStr( " (hash-table-delete! h 'k1)" ).should == "v1"
2366
- lambda { @nendo.evalStr( " (hash-table-get h 'k1)" ) }.should raise_error( RuntimeError )
2367
- @nendo.evalStr( " (hash-table-get h 'k1 #f) " ).should == "#f"
2368
- @nendo.evalStr( " (hash-table-num-entries h)" ).should == "1"
2369
- @nendo.evalStr( " (hash-table-clear! h)" ).should == "{}"
2370
- @nendo.evalStr( " (hash-table-num-entries h)" ).should == "0"
2371
- @nendo.evalStr( <<EOS
2372
- (set! h (hash-table eq?
2373
- '("a" "AAA")
2374
- '("b" "BBB")
2375
- '("c" "CCC" 100)))
2376
- (hash-table-keys h)
2377
- EOS
2378
- ).should == "(\"a\" \"b\" \"c\")"
2379
- @nendo.evalStr( <<EOS
2380
- (set! h (hash-table eq?
2381
- '("a" "AAA")
2382
- '("b" "BBB")
2383
- '("c" "CCC" 100)))
2384
- (hash-table-values h)
2385
- EOS
2386
- ).should == "((\"AAA\") (\"BBB\") (\"CCC\" 100))"
2387
- @nendo.evalStr( <<EOS
2388
- (set! h (hash-table eq?
2389
- '("a" . "AAA")
2390
- '("b" . "BBB")
2391
- '("c" . "CCC")))
2392
- h
2393
- EOS
2394
- ).should == "{\"a\"=>\"AAA\", \"b\"=>\"BBB\", \"c\"=>\"CCC\"}"
2395
- @nendo.evalStr( " (hash-table-keys h)" ).should == '("a" "b" "c")'
2396
- @nendo.evalStr( " (hash-table-values h)" ).should == '("AAA" "BBB" "CCC")'
2397
- @nendo.evalStr( " (hash-table-map h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
2398
- @nendo.evalStr( " (hash-table-for-each h (lambda (a b) (+ a b)))" ).should == '("aAAA" "bBBB" "cCCC")'
2399
- @nendo.evalStr( " (set! h (make-hash-table)) " ).should == "{}"
2400
- @nendo.evalStr( <<EOS
2401
- (set! h (hash-table eq?
2402
- '(true . 1)
2403
- '(false . 2)
2404
- '(nil . 3)))
2405
- h
2406
- EOS
2407
- ).should == "{true=>1, false=>2, nil=>3}"
2408
- @nendo.evalStr( " (hash-table-keys h) " ).should == "(#t #f nil)"
2409
- @nendo.evalStr( <<EOS
2410
- (set! h (hash-table eq?
2411
- '(1 . true)
2412
- '(2 . false)
2413
- '(3 . nil)))
2414
- h
2415
- EOS
2416
- ).should == "{1=>true, 2=>false, 3=>nil}"
2417
- @nendo.evalStr( " (hash-table-keys h) " ).should == "(1 2 3)"
2418
- end
2419
- end
2420
-
2421
- describe Nendo, "when use vector feature " do
2422
- before do
2423
- @nendo = Nendo::Core.new()
2424
- @nendo.setDisplayErrors( false )
2425
- @nendo.loadInitFile
2426
- end
2427
- it "should" do
2428
- @nendo.evalStr( " (define v (vector)) v" ).should == "#()"
2429
- @nendo.evalStr( " (vector? 1) " ).should == "#f"
2430
- @nendo.evalStr( " (vector? (vector)) " ).should == "#t"
2431
- @nendo.evalStr( " (vector? (vector 1)) " ).should == "#t"
2432
- @nendo.evalStr( " (vector? (vector 1 2)) " ).should == "#t"
2433
- @nendo.evalStr( " (vector? '#(1)) " ).should == "#t"
2434
- @nendo.evalStr( " (vector? '#(1 2)) " ).should == "#t"
2435
- @nendo.evalStr( " (vector? (Array.new)) " ).should == "#t"
2436
- @nendo.evalStr( " (vector? (Hash.new)) " ).should == "#f"
2437
- @nendo.evalStr( " (vector? 1.1) " ).should == "#f"
2438
- @nendo.evalStr( " (vector? \"str\") " ).should == "#f"
2439
- @nendo.evalStr( " (define v (make-vector 4))" ).should == "#(nil nil nil nil)"
2440
- @nendo.evalStr( " (vector-set! v 0 'v1) v" ).should == "#(v1 nil nil nil)"
2441
- @nendo.evalStr( " (vector-set! v 1 '100) v" ).should == "#(v1 100 nil nil)"
2442
- @nendo.evalStr( " (vector-set! v 2 '200) v" ).should == "#(v1 100 200 nil)"
2443
- @nendo.evalStr( " (vector-set! v 3 '(a b c)) v" ).should == "#(v1 100 200 (a b c))"
2444
- @nendo.evalStr( " (vector-length v)" ).should == "4"
2445
- @nendo.evalStr( " (vector-ref v 0) " ).should == "v1"
2446
- @nendo.evalStr( " (vector-ref v 1) " ).should == "100"
2447
- @nendo.evalStr( " (vector-ref v 2) " ).should == "200"
2448
- @nendo.evalStr( " (vector-ref v 3) " ).should == "(a b c)"
2449
- lambda { @nendo.evalStr( " (vector-ref v -1)" ) }.should raise_error( RuntimeError )
2450
- lambda { @nendo.evalStr( " (vector-ref v -2)" ) }.should raise_error( RuntimeError )
2451
- lambda { @nendo.evalStr( " (vector-ref v 5)" ) }.should raise_error( RuntimeError )
2452
- lambda { @nendo.evalStr( " (vector-ref v 6)" ) }.should raise_error( RuntimeError )
2453
- @nendo.evalStr( " (vector-ref v -1 1000)" ).should == "1000"
2454
- @nendo.evalStr( " (vector-ref v -2 2000)" ).should == "2000"
2455
- @nendo.evalStr( " (vector-ref v 5 3000)" ).should == "3000"
2456
- @nendo.evalStr( " (vector-ref v 6 4000)" ).should == "4000"
2457
- @nendo.evalStr( " (vector-ref v 7 #f)" ).should == "#f"
2458
- @nendo.evalStr( " (define v (make-vector 10)) v" ).should == "#(nil nil nil nil nil nil nil nil nil nil)"
2459
- @nendo.evalStr( " (vector->list v)" ).should == "(nil nil nil nil nil nil nil nil nil nil)"
2460
- @nendo.evalStr( " (define lst '(a b c (d)))" ).should == "(a b c (d))"
2461
- @nendo.evalStr( " (list->vector lst)" ).should == "#(a b c (d))"
2462
- @nendo.evalStr( " (list->vector (range 10 1))" ).should == "#(1 2 3 4 5 6 7 8 9 10)"
2463
- end
2464
- end
2465
-
2466
- describe Nendo, "tail call optimization " do
2467
- before do
2468
- @nendo = Nendo::Core.new()
2469
- @nendo.setDisplayErrors( false )
2470
- @nendo.loadInitFile
2471
- @nendo.loadInitFile # to self optimizing. The init.nnd file will be loaded twice, so `filter' can be optimized on second loading phase.
2472
- end
2473
- it "should" do
2474
- @nendo.evalStr( " (%setup-%tailcall-mark '(print \"abc\")) " ).should == "(%tailcall (print \"abc\"))"
2475
- @nendo.evalStr( " (%setup-%tailcall-mark '(begin (print \"abc\") 1 2 3)) " ).should == "(begin (print \"abc\") 1 2 3)"
2476
- @nendo.evalStr( " (%setup-%tailcall-mark '(begin 1 2 (print \"abc\") 3)) " ).should == "(begin 1 2 (print \"abc\") 3)"
2477
- @nendo.evalStr( " (%setup-%tailcall-mark '(begin 1 2 3 (print \"abc\"))) " ).should == "(begin 1 2 3 (%tailcall (print \"abc\")))"
2478
- @nendo.evalStr( " (%setup-%tailcall-mark '(lambda (x) x)) " ).should == "(lambda (x) x)"
2479
- @nendo.evalStr( " (%setup-%tailcall-mark '(macro (x) x)) " ).should == "(macro (x) x)"
2480
- @nendo.evalStr( " (%setup-%tailcall-mark '(%syntax (x) x)) " ).should == "(%syntax (x) x)"
2481
- @nendo.evalStr( " (%setup-%tailcall-mark '(%syntax (a b c) (begin a b c))) " ).should == "(%syntax (a b c) (begin a b c))"
2482
- @nendo.evalStr( " (%setup-%tailcall-mark '(lambda (x) (%syntax (y) x))) " ).should == "(lambda (x) (%syntax (y) x))"
2483
- @nendo.evalStr( " (%setup-%tailcall-mark '(lambda (x) (syntax-quote x))) " ).should == "(lambda (x) (quote x))"
2484
- @nendo.evalStr( " (%setup-%tailcall-mark '(lambda (x) (quote x))) " ).should == "(lambda (x) (quote x))"
2485
- @nendo.evalStr( <<EOS
2486
- (%setup-%tailcall-mark
2487
- '(lambda '(x)
2488
- 1
2489
- 2
2490
- (print \"abc\")))
2491
- EOS
2492
- ).should == "(lambda (quote (x)) 1 2 (%tailcall (print \"abc\")))"
2493
- @nendo.evalStr( <<EOS
2494
- (%setup-%tailcall-mark
2495
- '(lambda (x)
2496
- 1
2497
- 2
2498
- (if #t
2499
- (begin 1 2 (print "abc"))
2500
- (begin 1 2 (print "ABC")))))
2501
- EOS
2502
- ).should == "(lambda (x) 1 2 (if #t (begin 1 2 (%tailcall (print \"abc\"))) (begin 1 2 (%tailcall (print \"ABC\")))))"
2503
- @nendo.evalStr( <<EOS
2504
- (%setup-%tailcall-mark (macroexpand
2505
- '(define (foo) (foo))
2506
- ))
2507
- EOS
2508
- ).should == "(define foo (lambda () (%tailcall (foo))))"
2509
- @nendo.evalStr( <<EOS
2510
- (%setup-%tailcall-mark (macroexpand
2511
- '(values? (make-values '()))
2512
- ))
2513
- EOS
2514
- ).should == "(%tailcall (values? (make-values (quote ()))))"
2515
- @nendo.evalStr( <<EOS
2516
- (%setup-%tailcall-mark (macroexpand
2517
- '(cond
2518
- (false 1)
2519
- (false 2))
2520
- ))
2521
- EOS
2522
- ).should == "(if #f (begin 1) (if #f (begin 2) ()))"
2523
- @nendo.evalStr( <<EOS
2524
- (%setup-%tailcall-mark (macroexpand
2525
- '(cond
2526
- (false 1)
2527
- (false 2)
2528
- (else 3))
2529
- ))
2530
- EOS
2531
- ).should == "(if #f (begin 1) (if #f (begin 2) (if #t (begin 3) ())))"
2532
- @nendo.evalStr( <<EOS
2533
- (%setup-%tailcall-mark (macroexpand
2534
- '(and
2535
- (foo 1)
2536
- (bar 2))
2537
- ))
2538
- EOS
2539
- ).should == "(if (not (eq? #f (foo 1))) (%tailcall (bar 2)) #f)"
2540
- @nendo.evalStr( <<EOS
2541
- (%setup-%tailcall-mark (macroexpand
2542
- '(or
2543
- (foo 1)
2544
- (bar 2))
2545
- ))
2546
- EOS
2547
- ).gsub( /_[0-9][0-9][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))))"
2548
- @nendo.evalStr( <<EOS
2549
- (%setup-%tailcall-mark (macroexpand
2550
- '(let loop ((x 1))
2551
- 1
2552
- 2
2553
- (loop 100))
2554
- ))
2555
- EOS
2556
- ).should == "(letrec ((loop (lambda (x) 1 2 (%tailcall (loop 100))))) (%tailcall (loop 1)))"
2557
- @nendo.evalStr( "(%setup-%tailcall-mark (macroexpand "+
2558
- " '(let1 aaa 111 aaa)"+
2559
- " ))" ).should == "(%let ((aaa 111)) aaa)"
2560
- @nendo.evalStr( <<EOS
2561
- (%setup-%tailcall-mark
2562
- '(letrec ((func1
2563
- (lambda (x)
2564
- 1
2565
- (func2)))
2566
- (func2
2567
- (lambda (x)
2568
- 2
2569
- (func1))))
2570
- (func1 100)))
2571
- EOS
2572
- ).should == "(letrec ((func1 (lambda (x) 1 (%tailcall (func2)))) (func2 (lambda (x) 2 (%tailcall (func1))))) (%tailcall (func1 100)))"
2573
- @nendo.evalStr( "(set-optimize-level 0) " ).should == "0"
2574
- lambda { @nendo.evalStr( <<EOS
2575
- (filter
2576
- (lambda (x) (< x 10))
2577
- (range 10000))
2578
- EOS
2579
- ) }.should raise_error(SystemStackError)
2580
- @nendo.evalStr( "(set-optimize-level 1) " ).should == "1"
2581
- @nendo.evalStr( <<EOS
2582
- (apply +
2583
- (map
2584
- (lambda (x) (* x 2))
2585
- (range 10000)))
2586
- EOS
2587
- ).should == "99990000"
2588
- @nendo.evalStr( <<EOS
2589
- (filter
2590
- (lambda (x) (< x 10))
2591
- (range 1000))
2592
- EOS
2593
- ).should == "(0 1 2 3 4 5 6 7 8 9)"
2594
- @nendo.evalStr( <<EOS
2595
- (filter-map
2596
- (lambda (x)
2597
- (when (< x 10) (- x)))
2598
- (range 1000))
2599
- EOS
2600
- ).should == "(0 -1 -2 -3 -4 -5 -6 -7 -8 -9)"
2601
- @nendo.evalStr( <<EOS
2602
- (define str
2603
- (if #t
2604
- (car '("a"))
2605
- (car '("b"))))
2606
- (sprintf "A%sZ" str)
2607
- EOS
2608
- ).should == '"AaZ"'
2609
- @nendo.evalStr( <<EOS
2610
- (letrec ((str (if #t
2611
- (+ "a" "A")
2612
- '())))
2613
- str.class)
2614
- EOS
2615
- ).should == 'String'
2616
- @nendo.evalStr( <<EOS
2617
- (letrec ((str
2618
- (if #t
2619
- (+ \"a\" \"A\")
2620
- '())))
2621
- (+ str \"...\"))
2622
- EOS
2623
- ).should == '"aA..."'
2624
- end
2625
- end
2626
-
2627
-
2628
- describe Nendo, "When use optional argument parser " do
2629
- before do
2630
- @nendo = Nendo::Core.new()
2631
- @nendo.loadInitFile
2632
- end
2633
- it "should" do
2634
- @nendo.evalStr( " (get-optional '() 100) " ).should == "100"
2635
- @nendo.evalStr( " (get-optional '(1) 100) " ).should == "1"
2636
- @nendo.evalStr( " (get-optional '(2) 100) " ).should == "2"
2637
- @nendo.evalStr( " (get-optional '(3 4) 100) " ).should == "3"
2638
- @nendo.evalStr( " (get-optional '() #t) " ).should == "#t"
2639
- @nendo.evalStr( " (get-optional '() #f) " ).should == "#f"
2640
- end
2641
- end
2642
-
2643
- describe Nendo, "When use :optional argument feature " do
2644
- before do
2645
- @nendo = Nendo::Core.new()
2646
- @nendo.setDisplayErrors( false )
2647
- @nendo.loadInitFile
2648
- end
2649
- it "should" do
2650
- @nendo.evalStr( '(define (func arg1 arg2) (list arg1 arg2)) (func 1 2)' ).should == "(1 2)"
2651
- @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #f)) (list arg1 arg2 arg3)) (func 1 2)' ).should == "(1 2 #f)"
2652
- @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #t)) (list arg1 arg2 arg3)) (func 1 2)' ).should == "(1 2 #t)"
2653
- @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3)) (func 1 2)' ).should == "(1 2 3)"
2654
- @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #f)) (list arg1 arg2 arg3)) (func 1 2 30)' ).should == "(1 2 30)"
2655
- @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 #t)) (list arg1 arg2 arg3)) (func 1 2 40)' ).should == "(1 2 40)"
2656
- @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3)) (func 1 2 50)' ).should == "(1 2 50)"
2657
- @nendo.evalStr( '(define (func arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3)) (func 1 2 "String")' ).should == '(1 2 "String")'
2658
-
2659
- @nendo.evalStr( '(define func (lambda (arg1 arg2) (list arg1 arg2))) (func 1 2)' ).should == '(1 2)'
2660
- lambda { @nendo.evalStr( '(define func (lambda (arg1 arg2 :optional (arg3 #f)) (list arg1 arg2 arg3))) (func 1 2)' ) }.should raise_error( RuntimeError, /handle keyword argument/ )
2661
- lambda { @nendo.evalStr( '(define func (lambda (arg1 arg2 :optional (arg3 #t)) (list arg1 arg2 arg3))) (func 1 2)' ) }.should raise_error( RuntimeError, /handle keyword argument/ )
2662
- lambda { @nendo.evalStr( '(define func (lambda (arg1 arg2 :optional (arg3 3)) (list arg1 arg2 arg3))) (func 1 2)' ) }.should raise_error( RuntimeError, /handle keyword argument/ )
2663
- end
2664
- end
2665
-
2666
-
2667
- describe Nendo, "when use export-to-ruby macro " do
2668
- before do
2669
- @nendo = Nendo::Core.new()
2670
- @nendo.setDisplayErrors( false )
2671
- @nendo.loadInitFile
2672
- end
2673
- it "should" do
2674
- @nendo.evalStr( " (define (nendo_function0 ) 0) #t" ).should == "#t"
2675
- @nendo.evalStr( " (define (nendo_function1 x) (+ x 1)) #t" ).should == "#t"
2676
- @nendo.evalStr( " (define (nendo_function2 x y) (* x y)) #t" ).should == "#t"
2677
- @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"
2678
- @nendo.evalStr( " (export-to-ruby nendo_function0) " ).should == "#t"
2679
- @nendo.evalStr( " (export-to-ruby nendo_function1) " ).should == "#t"
2680
- @nendo.evalStr( " (export-to-ruby nendo_function2) " ).should == "#t"
2681
- @nendo.evalStr( " (export-to-ruby nendo_function7) " ).should == "#t"
2682
- @nendo.evalStr( " (macroexpand '(export-to-ruby nendo_function1)) " ).should == '(%export-to-ruby "nendo_function1" nendo_function1)'
2683
- @nendo.evalStr( " (macroexpand '(export-to-ruby nendo_function7)) " ).should == '(%export-to-ruby "nendo_function7" nendo_function7)'
2684
- @nendo.evalStr( " (define (a-func0) 0) #t" ).should == "#t"
2685
- lambda { @nendo.evalStr( " (export-to-ruby a-func0) " ) }.should raise_error(ArgumentError)
2686
- @nendo.evalStr( " (define (clone) 0) #t" ).should == "#t"
2687
- lambda { @nendo.evalStr( " (export-to-ruby clone) " ) }.should raise_error(RuntimeError)
2688
- @nendo.evalStr( " (define variable_a 0) #t" ).should == "#t"
2689
- lambda { @nendo.evalStr( " (export-to-ruby variable_a) " ) }.should raise_error(ArgumentError)
2690
- @nendo.nendo_function0.should == 0
2691
- @nendo.nendo_function1( 10 ).should == 11
2692
- @nendo.nendo_function2( 8, 9 ).should == 72
2693
- @nendo.nendo_function7( 7,6,5,4,3,2,1 ).should === [ 7,6,5,4,3,2,1 ]
2694
- end
2695
- end