Module: BuiltinFunctions
- Included in:
- Evaluator
- Defined in:
- lib/nendo.rb
Overview
built-in functions
Instance Method Summary collapse
- #__assertFlat(*args) ⇒ Object
- #__assertList(funcname, arg) ⇒ Object
- #_car(cell) ⇒ Object
- #_cdr(cell) ⇒ Object
- #_cons(first, second) ⇒ Object
- #_display(arg) ⇒ Object
- #_div(first, *rest) ⇒ Object
- #_eq_QMARK(a, b) ⇒ Object
- #_equal_QMARK(a, b) ⇒ Object
- #_eqv_QMARK(a, b) ⇒ Object
- #_exit(*args) ⇒ Object
- #_ge_QMARK(a, b) ⇒ Object
- #_gt_QMARK(a, b) ⇒ Object
- #_intern(arg) ⇒ Object
- #_le_QMARK(a, b) ⇒ Object
- #_length(arg) ⇒ Object
- #_list(*args) ⇒ Object
- #_lt_QMARK(a, b) ⇒ Object
- #_macro_QMARK(arg) ⇒ Object
- #_macroexpand_1(arg) ⇒ Object
- #_minus(first, *rest) ⇒ Object
- #_mod(first, *rest) ⇒ Object
- #_multi(first, *rest) ⇒ Object
- #_newline ⇒ Object
- #_not(arg) ⇒ Object
- #_null_QMARK(arg) ⇒ Object
- #_number_QMARK(arg) ⇒ Object
- #_pair_QMARK(arg) ⇒ Object
- #_plus(first, *rest) ⇒ Object
- #_print(arg) ⇒ Object
- #_printf(format, *rest) ⇒ Object
- #_procedure_QMARK(arg) ⇒ Object
- #_range(num) ⇒ Object
- #_read(*args) ⇒ Object
- #_require(arg) ⇒ Object
- #_reverse(arg) ⇒ Object
- #_sort(arg) ⇒ Object
- #_sprintf(format, *rest) ⇒ Object
- #_string_join(lst, delim) ⇒ Object
- #_string_QMARK(arg) ⇒ Object
- #_symbol_QMARK(arg) ⇒ Object
- #_to_list(arg) ⇒ Object
- #_to_s(arg) ⇒ Object
- #_uniq(arg) ⇒ Object
- #_write(arg) ⇒ Object
- #_write_to_string(arg) ⇒ Object
Instance Method Details
#__assertFlat(*args) ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/nendo.rb', line 479 def __assertFlat( *args ) if 0 == args.length raise ArgumentError, "Error: + - * / % operator got illegal argument. " else args.each { |x| if Cell == x.class or Nil == x.class raise ArgumentError, "Error: + - * / % operator got illegal argument. " end } end end |
#__assertList(funcname, arg) ⇒ Object
491 492 493 494 495 |
# File 'lib/nendo.rb', line 491 def __assertList( funcname, arg ) if Cell != arg.class raise ArgumentError, "Error: %s expects a list argument.\n" end end |
#_car(cell) ⇒ Object
627 |
# File 'lib/nendo.rb', line 627 def _car( cell ) cell.car end |
#_cdr(cell) ⇒ Object
628 |
# File 'lib/nendo.rb', line 628 def _cdr( cell ) cell.cdr end |
#_cons(first, second) ⇒ Object
573 574 575 |
# File 'lib/nendo.rb', line 573 def _cons( first, second ) Cell.new( first, second ) end |
#_display(arg) ⇒ Object
631 |
# File 'lib/nendo.rb', line 631 def _display( arg ) printer = Printer.new ; print printer._print( arg ) ; arg end |
#_div(first, *rest) ⇒ Object
546 547 548 549 550 551 552 553 554 555 |
# File 'lib/nendo.rb', line 546 def _div( first, *rest ) raise TypeError if not _number_QMARK(first) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length 1 / first else rest.inject(first){|x,y| x/y} end end |
#_eq_QMARK(a, b) ⇒ Object
621 |
# File 'lib/nendo.rb', line 621 def _eq_QMARK( a,b ) a == b end |
#_equal_QMARK(a, b) ⇒ Object
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/nendo.rb', line 497 def _equal_QMARK( a, b ) if a.class != b.class false elsif a.class == Cell if a.isNull and b.isNull true else _equal_QMARK( a.car, b.car ) and _equal_QMARK( a.cdr, b.cdr ) end elsif a.class == Nil and b.class == Nil true else (a === b) end end |
#_eqv_QMARK(a, b) ⇒ Object
626 |
# File 'lib/nendo.rb', line 626 def _eqv_QMARK( a,b ) a === b end |
#_exit(*args) ⇒ Object
577 578 579 580 581 582 583 584 |
# File 'lib/nendo.rb', line 577 def _exit( *args ) if 0 == args[0].length Kernel::exit(0) else arr = args[0].to_arr Kernel::exit(arr[0]) end end |
#_ge_QMARK(a, b) ⇒ Object
623 |
# File 'lib/nendo.rb', line 623 def _ge_QMARK( a,b ) a >= b end |
#_gt_QMARK(a, b) ⇒ Object
622 |
# File 'lib/nendo.rb', line 622 def _gt_QMARK( a,b ) a > b end |
#_intern(arg) ⇒ Object
664 |
# File 'lib/nendo.rb', line 664 def _intern( arg ) arg.intern end |
#_le_QMARK(a, b) ⇒ Object
625 |
# File 'lib/nendo.rb', line 625 def _le_QMARK( a,b ) a <= b end |
#_length(arg) ⇒ Object
607 608 609 610 611 612 613 614 615 |
# File 'lib/nendo.rb', line 607 def _length( arg ) if _null_QMARK( arg ) 0 elsif arg.is_a? Cell arg.length else raise TypeError end end |
#_list(*args) ⇒ Object
616 |
# File 'lib/nendo.rb', line 616 def _list( *args) args[0] end |
#_lt_QMARK(a, b) ⇒ Object
624 |
# File 'lib/nendo.rb', line 624 def _lt_QMARK( a,b ) a < b end |
#_macro_QMARK(arg) ⇒ Object
635 |
# File 'lib/nendo.rb', line 635 def _macro_QMARK( arg ) (LispMacro == arg.class) end |
#_macroexpand_1(arg) ⇒ Object
646 647 648 649 650 651 652 |
# File 'lib/nendo.rb', line 646 def ( arg ) if _pair_QMARK( arg ) ( arg ) else arg end end |
#_minus(first, *rest) ⇒ Object
524 525 526 527 528 529 530 531 532 533 |
# File 'lib/nendo.rb', line 524 def _minus( first, *rest ) raise TypeError if not (_number_QMARK(first) or _string_QMARK(first)) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length - first else rest.inject(first){|x,y| x-y} end end |
#_mod(first, *rest) ⇒ Object
557 558 559 560 561 562 563 564 565 566 |
# File 'lib/nendo.rb', line 557 def _mod( first, *rest ) raise TypeError if not _number_QMARK(first) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length 1 % first else rest.inject(first){|x,y| x%y} end end |
#_multi(first, *rest) ⇒ Object
535 536 537 538 539 540 541 542 543 544 |
# File 'lib/nendo.rb', line 535 def _multi( first, *rest ) raise TypeError if not _number_QMARK(first) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length first else rest.inject(first){|x,y| x*y} end end |
#_newline ⇒ Object
633 |
# File 'lib/nendo.rb', line 633 def _newline( ) print "\n" end |
#_not(arg) ⇒ Object
568 569 570 571 |
# File 'lib/nendo.rb', line 568 def _not( arg ) arg = false if Nil == arg.class not arg end |
#_null_QMARK(arg) ⇒ Object
598 599 600 601 602 603 604 605 606 |
# File 'lib/nendo.rb', line 598 def _null_QMARK( arg ) if Nil == arg.class true elsif Cell == arg.class arg.isNull else false end end |
#_number_QMARK(arg) ⇒ Object
644 |
# File 'lib/nendo.rb', line 644 def _number_QMARK( arg ) ((Fixnum == arg.class) or (Float == arg.class)) end |
#_pair_QMARK(arg) ⇒ Object
637 638 639 640 641 642 643 |
# File 'lib/nendo.rb', line 637 def _pair_QMARK( arg ) if _null_QMARK( arg ) false else (Cell == arg.class) end end |
#_plus(first, *rest) ⇒ Object
513 514 515 516 517 518 519 520 521 522 |
# File 'lib/nendo.rb', line 513 def _plus( first, *rest ) raise TypeError if not (_number_QMARK(first) or _string_QMARK(first)) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length first else rest.inject(first){|x,y| x+y} end end |
#_print(arg) ⇒ Object
586 587 588 |
# File 'lib/nendo.rb', line 586 def _print( format, *rest ) print( format, *(rest[0].to_arr) ) end |
#_printf(format, *rest) ⇒ Object
590 591 592 |
# File 'lib/nendo.rb', line 590 def _printf( format, *rest ) Kernel::printf( format, *(rest[0].to_arr) ) end |
#_procedure_QMARK(arg) ⇒ Object
634 |
# File 'lib/nendo.rb', line 634 def _procedure_QMARK( arg ) ((Proc == arg.class) or (Method == arg.class)) end |
#_range(num) ⇒ Object
620 |
# File 'lib/nendo.rb', line 620 def _range( num ) (0..num-1).to_a.to_list end |
#_read(*args) ⇒ Object
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/nendo.rb', line 669 def _read( *args ) lst = args[0].to_arr io = if 0 == lst.length STDIN else lst[0] end reader = Reader.new( io, "STDIN", false ) ret = nil begin s = reader._read ret = s[0] if s[1] # EOF? ret = Cell.new break end end until s[2] ret end |
#_require(arg) ⇒ Object
668 |
# File 'lib/nendo.rb', line 668 def _require( arg ) Kernel::require( arg ) end |
#_reverse(arg) ⇒ Object
618 |
# File 'lib/nendo.rb', line 618 def _reverse( arg ) arg.to_arr.reverse.to_list end |
#_sort(arg) ⇒ Object
617 |
# File 'lib/nendo.rb', line 617 def _sort( arg ) arg.to_arr.sort.to_list end |
#_sprintf(format, *rest) ⇒ Object
594 595 596 |
# File 'lib/nendo.rb', line 594 def _sprintf( format, *rest ) Kernel::sprintf( format, *(rest[0].to_arr) ) end |
#_string_join(lst, delim) ⇒ Object
665 666 667 |
# File 'lib/nendo.rb', line 665 def _string_join( lst, delim ) lst.to_a.map{ |x| x.car }.join( delim ) end |
#_string_QMARK(arg) ⇒ Object
645 |
# File 'lib/nendo.rb', line 645 def _string_QMARK( arg ) String == arg.class end |
#_symbol_QMARK(arg) ⇒ Object
636 |
# File 'lib/nendo.rb', line 636 def _symbol_QMARK( arg ) (Symbol == arg.class) end |
#_to_list(arg) ⇒ Object
654 655 656 657 658 659 660 661 662 663 |
# File 'lib/nendo.rb', line 654 def _to_list( arg ) case arg when Array arg.to_list when Cell arg else raise TypeError end end |
#_to_s(arg) ⇒ Object
653 |
# File 'lib/nendo.rb', line 653 def _to_s( arg ) arg.to_s end |
#_uniq(arg) ⇒ Object
619 |
# File 'lib/nendo.rb', line 619 def _uniq( arg ) arg.to_arr.uniq.to_list end |
#_write(arg) ⇒ Object
629 |
# File 'lib/nendo.rb', line 629 def _write( arg ) printer = Printer.new ; print printer._write( arg ) ; arg end |
#_write_to_string(arg) ⇒ Object
630 |
# File 'lib/nendo.rb', line 630 def _write_to_string( arg ) printer = Printer.new ; printer._write( arg ) end |