Module: Nendo::BuiltinFunctions
- Included in:
- Evaluator
- Defined in:
- lib/nendo/ruby/builtin_functions.rb
Overview
built-in functions
Instance Method Summary collapse
- #__ASMARK(*args) ⇒ Object
- #__ASMARK_ARGS0 ⇒ Object
- #__ASMARK_ARGS1(a) ⇒ Object
- #__ASMARK_ARGS2(a, b) ⇒ Object
- #__ASMARK_ARGS3(a, b, c) ⇒ Object
- #__ASMARKFILE_ASMARK ⇒ Object
- #__ASMARKLINE_ASMARK ⇒ Object
- #__ASMARKruntime_MIMARKcheck_ASMARK ⇒ Object
- #__assertFlat(*args) ⇒ Object
- #__assertList(funcname, arg) ⇒ Object
- #__EQMARK(a, b) ⇒ Object
- #__GTMARK(a, b) ⇒ Object
- #__GTMARK_EQMARK(a, b) ⇒ Object
- #__LTMARK(a, b) ⇒ Object
- #__LTMARK_EQMARK(a, b) ⇒ Object
- #__MIMARK(first, *rest) ⇒ Object
- #__MIMARK_ARGS0 ⇒ Object
- #__MIMARK_ARGS1(a) ⇒ Object
- #__MIMARK_ARGS2(a, b) ⇒ Object
- #__MIMARK_ARGS3(a, b, c) ⇒ Object
- #__PAMARK(first, *rest) ⇒ Object
- #__PAMARKlist_QUMARK(arg) ⇒ Object
-
#__PAMARKraise(exception, message, backtrace) ⇒ Object
backtrace expects this format “filename:lineno: place message ”.
- #__PLMARK(*args) ⇒ Object
- #__PLMARK_ARGS0 ⇒ Object
- #__PLMARK_ARGS1(a) ⇒ Object
- #__PLMARK_ARGS2(a, b) ⇒ Object
- #__PLMARK_ARGS3(a, b, c) ⇒ Object
- #__SLMARK(first, *rest) ⇒ Object
- #_apply1(first, arg) ⇒ Object
- #_car(cell) ⇒ Object
- #_cdr(cell) ⇒ Object
- #_cons(first, second) ⇒ Object
- #_core_MIMARKsyntax_QUMARK(arg) ⇒ Object
- #_display(arg) ⇒ Object
- #_eq_QUMARK(a, b) ⇒ Object
- #_equal_QUMARK(a, b) ⇒ Object
- #_eqv_QUMARK(a, b) ⇒ Object
- #_exit(*args) ⇒ Object
- #_ge_QUMARK(a, b) ⇒ Object
- #_global_MIMARKvariables ⇒ Object
- #_gt_QUMARK(a, b) ⇒ Object
- #_hash_MIMARKtable_MIMARKexist_QUMARK(h, key) ⇒ Object
- #_hash_MIMARKtable_MIMARKget(h, key, *args) ⇒ Object
- #_hash_MIMARKtable_MIMARKput_EXMARK(h, key, value) ⇒ Object
- #_integer_QUMARK(arg) ⇒ Object
- #_intern(arg) ⇒ Object
- #_keyword_MIMARK_GTMARKstring(arg) ⇒ Object
- #_keyword_QUMARK(arg) ⇒ Object
- #_le_QUMARK(a, b) ⇒ Object
- #_length(arg) ⇒ Object
- #_list(*args) ⇒ Object
- #_lt_QUMARK(a, b) ⇒ Object
- #_macro_QUMARK(arg) ⇒ Object
- #_macroexpand_MIMARK1(arg) ⇒ Object
- #_make_MIMARKkeyword(arg) ⇒ Object
- #_make_MIMARKrecord_MIMARKtype(name, field_names) ⇒ Object
- #_make_MIMARKvalues(lst) ⇒ Object
- #_modulo(first, *rest) ⇒ Object
- #_newline ⇒ Object
- #_nil_QUMARK(arg) ⇒ Object
- #_not(arg) ⇒ Object
- #_null_QUMARK(arg) ⇒ Object
- #_number_QUMARK(arg) ⇒ Object
- #_pair_QUMARK(arg) ⇒ Object
- #_print(arg) ⇒ Object
- #_printf(format, *rest) ⇒ Object
- #_procedure_QUMARK(arg) ⇒ Object
- #_quotient(first, second) ⇒ Object
- #_range(num, *args) ⇒ Object
- #_read(*args) ⇒ Object
- #_read_MIMARKfrom_MIMARKstring(str) ⇒ Object
- #_remainder(first, second) ⇒ Object
- #_require(arg) ⇒ Object
- #_reverse(arg) ⇒ Object
- #_set_MIMARKcar_EXMARK(cell, arg) ⇒ Object
- #_set_MIMARKcdr_EXMARK(cell, arg) ⇒ Object
- #_sprintf(format, *rest) ⇒ Object
- #_string_MIMARK_GTMARKsymbol(arg) ⇒ Object
- #_string_MIMARKjoin(lst, *args) ⇒ Object
- #_string_QUMARK(arg) ⇒ Object
- #_symbol_MIMARK_GTMARKstring(arg) ⇒ Object
- #_symbol_QUMARK(arg) ⇒ Object
- #_syntax_QUMARK(arg) ⇒ Object
- #_to_arr(arg) ⇒ Object
- #_to_i(arg) ⇒ Object
- #_to_list(arg) ⇒ Object
- #_to_MIMARKarr(arg) ⇒ Object
- #_to_MIMARKi(arg) ⇒ Object
- #_to_MIMARKlist(arg) ⇒ Object
- #_to_MIMARKs(arg) ⇒ Object
- #_to_s(arg) ⇒ Object
- #_uniq(arg) ⇒ Object
- #_values_MIMARKvalues(arg) ⇒ Object
- #_values_QUMARK(arg) ⇒ Object
- #_vector_MIMARKset_EXMARK(v, index, value) ⇒ Object
- #_write(arg) ⇒ Object
- #_write_MIMARKto_MIMARKstring(arg) ⇒ Object (also: #write_to_string)
Instance Method Details
#__ASMARK(*args) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 107 def __ASMARK( *args ) arr = args[0].to_arr case args[0].length when 0 1 else __assertFlat( arr ) arr.each { |x| if not _number_QUMARK(x) raise TypeError end } case args[0].length when 1 args[0].car else arr[1..-1].inject(arr[0]){|x,y| x*y} end end end |
#__ASMARK_ARGS0 ⇒ Object
102 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 102 def __ASMARK_ARGS0( ) 1 end |
#__ASMARK_ARGS1(a) ⇒ Object
103 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 103 def __ASMARK_ARGS1( a ) a end |
#__ASMARK_ARGS2(a, b) ⇒ Object
104 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 104 def __ASMARK_ARGS2( a, b ) a * b end |
#__ASMARK_ARGS3(a, b, c) ⇒ Object
105 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 105 def __ASMARK_ARGS3( a, b, c ) a * b * c end |
#__ASMARKFILE_ASMARK ⇒ Object
506 507 508 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 506 def __ASMARKFILE_ASMARK() @lastSourcefile end |
#__ASMARKLINE_ASMARK ⇒ Object
502 503 504 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 502 def __ASMARKLINE_ASMARK() @lastLineno end |
#__ASMARKruntime_MIMARKcheck_ASMARK ⇒ Object
510 511 512 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 510 def __ASMARKruntime_MIMARKcheck_ASMARK() @runtimeCheck end |
#__assertFlat(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 39 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
51 52 53 54 55 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 51 def __assertList( funcname, arg ) if Cell != arg.class raise ArgumentError, "Error: %s expects a list argument.\n" end end |
#__EQMARK(a, b) ⇒ Object
279 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 279 def __EQMARK( a,b ) _equal_QUMARK( a, b ) end |
#__GTMARK(a, b) ⇒ Object
280 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 280 def __GTMARK( a,b ) a > b end |
#__GTMARK_EQMARK(a, b) ⇒ Object
281 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 281 def __GTMARK_EQMARK( a,b ) a >= b end |
#__LTMARK(a, b) ⇒ Object
282 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 282 def __LTMARK( a,b ) a < b end |
#__LTMARK_EQMARK(a, b) ⇒ Object
283 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 283 def __LTMARK_EQMARK( a,b ) a <= b end |
#__MIMARK(first, *rest) ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 133 def __MIMARK( first, *rest ) raise TypeError if not _number_QUMARK(first) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length - first else rest.inject(first){|x,y| x-y} end end |
#__MIMARK_ARGS0 ⇒ Object
128 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 128 def __MIMARK_ARGS0( ) 0 end |
#__MIMARK_ARGS1(a) ⇒ Object
129 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 129 def __MIMARK_ARGS1( a ) -a end |
#__MIMARK_ARGS2(a, b) ⇒ Object
130 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 130 def __MIMARK_ARGS2( a, b ) a - b end |
#__MIMARK_ARGS3(a, b, c) ⇒ Object
131 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 131 def __MIMARK_ARGS3( a, b, c ) a - b - c end |
#__PAMARK(first, *rest) ⇒ Object
155 156 157 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 155 def __PAMARK( first, *rest ) _modulo( first, *rest ) end |
#__PAMARKlist_QUMARK(arg) ⇒ Object
331 332 333 334 335 336 337 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 331 def __PAMARKlist_QUMARK( arg ) if _pair_QUMARK( arg ) (not arg.lastAtom) and (1 <= arg.to_arr.size) # it means proper list? else _null_QUMARK( arg ) end end |
#__PAMARKraise(exception, message, backtrace) ⇒ Object
backtrace expects this format “filename:lineno: place message ”. e.g. “init.nnd:10: in aaa macro.”.
498 499 500 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 498 def __PAMARKraise( exception, , backtrace ) raise exception, , [ backtrace ] end |
#__PLMARK(*args) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 80 def __PLMARK( *args ) arr = args[0].to_arr case args[0].length when 0 0 else __assertFlat( arr ) arr.each { |x| if not (_number_QUMARK(x) or _string_QUMARK(x)) ##arr.each { |v| STDERR.printf( "__PLMARK: %s\n", v ) } raise TypeError, sprintf( "Error: arg %s is [%s] type",x ,x.class ) end } case args[0].length when 1 args[0].car else arr[1..-1].inject(arr[0]){|x,y| x+y} end end end |
#__PLMARK_ARGS0 ⇒ Object
75 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 75 def __PLMARK_ARGS0( ) 0 end |
#__PLMARK_ARGS1(a) ⇒ Object
76 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 76 def __PLMARK_ARGS1( a ) a end |
#__PLMARK_ARGS2(a, b) ⇒ Object
77 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 77 def __PLMARK_ARGS2( a, b ) a + b end |
#__PLMARK_ARGS3(a, b, c) ⇒ Object
78 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 78 def __PLMARK_ARGS3( a, b, c ) a + b + c end |
#__SLMARK(first, *rest) ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 144 def __SLMARK( first, *rest ) raise TypeError if not _number_QUMARK(first) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length 1 / first else rest.inject(first){|x,y| x/y} end end |
#_apply1(first, arg) ⇒ Object
427 428 429 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 427 def _apply1( first, arg ) trampCall( callProcedure( nil, "(apply1 genereate func)", first, arg.to_arr )) end |
#_car(cell) ⇒ Object
298 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 298 def _car( cell ) cell.car end |
#_cdr(cell) ⇒ Object
299 300 301 302 303 304 305 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 299 def _cdr( cell ) if cell.cdr.is_a? Nil Cell.new else cell.cdr end end |
#_cons(first, second) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 187 def _cons( first, second ) if first.is_a? Nil first = Cell.new end if second.is_a? Cell if second.isNull Cell.new( first ) else Cell.new( first, second ) end else Cell.new( first, second ) end end |
#_core_MIMARKsyntax_QUMARK(arg) ⇒ Object
317 318 319 320 321 322 323 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 317 def _core_MIMARKsyntax_QUMARK( arg ) if arg.is_a? LispCoreSyntax arg.syntaxName else nil end end |
#_display(arg) ⇒ Object
309 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 309 def _display( arg ) printer = Printer.new ; print printer._print( arg ) ; arg end |
#_eq_QUMARK(a, b) ⇒ Object
284 285 286 287 288 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 284 def _eq_QUMARK( a,b ) a = a.intern if a.class == ParsedSymbol b = b.intern if b.class == ParsedSymbol a.equal?( b ) end |
#_equal_QUMARK(a, b) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 57 def _equal_QUMARK( a, b ) a = a.intern if a.class == ParsedSymbol b = b.intern if b.class == ParsedSymbol if a.is_a? String and b.is_a? String a == b elsif a.class != b.class false elsif a.is_a? Cell _equal_QUMARK( a.car, b.car ) and _equal_QUMARK( a.cdr, b.cdr ) elsif _null_QUMARK( a ) and _null_QUMARK( b ) true elsif a.is_a? Proc a == b else (a == b) end end |
#_eqv_QUMARK(a, b) ⇒ Object
293 294 295 296 297 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 293 def _eqv_QUMARK( a,b ) a = a.intern if a.class == ParsedSymbol b = b.intern if b.class == ParsedSymbol a == b end |
#_exit(*args) ⇒ Object
225 226 227 228 229 230 231 232 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 225 def _exit( *args ) if 0 == args[0].length Kernel::exit(0) else arr = args[0].to_arr Kernel::exit(arr[0]) end end |
#_ge_QUMARK(a, b) ⇒ Object
290 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 290 def _ge_QUMARK( a,b ) a >= b end |
#_global_MIMARKvariables ⇒ Object
431 432 433 434 435 436 437 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 431 def _global_MIMARKvariables self.instance_variables.select { |x| x.match( /^[@]_[_a-zA-Z]/ ) }.map{ |name| self.toLispSymbol( name[1..-1] ).intern }.to_list end |
#_gt_QUMARK(a, b) ⇒ Object
289 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 289 def _gt_QUMARK( a,b ) a > b end |
#_hash_MIMARKtable_MIMARKexist_QUMARK(h, key) ⇒ Object
492 493 494 495 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 492 def _hash_MIMARKtable_MIMARKexist_QUMARK( h, key ) # don't use h.has_key(k), because has_key method undefined on some database bindings. (e.g. KyotoCabinet) h[key] ? true : false end |
#_hash_MIMARKtable_MIMARKget(h, key, *args) ⇒ Object
475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 475 def _hash_MIMARKtable_MIMARKget( h, key, *args ) if h.has_key?(key) h[key] else arr = args[0].to_arr if 0 < arr.length arr[0] else raise RuntimeError, sprintf( "Error: in hash-table-get() key [%s] was not exist.\n", key ) end end end |
#_hash_MIMARKtable_MIMARKput_EXMARK(h, key, value) ⇒ Object
488 489 490 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 488 def _hash_MIMARKtable_MIMARKput_EXMARK( h, key, value ) h[key] = value end |
#_integer_QUMARK(arg) ⇒ Object
338 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 338 def _integer_QUMARK( arg ) arg.is_a? Integer end |
#_intern(arg) ⇒ Object
378 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 378 def _intern( arg ) arg.intern end |
#_keyword_MIMARK_GTMARKstring(arg) ⇒ Object
467 468 469 470 471 472 473 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 467 def _keyword_MIMARK_GTMARKstring( arg ) if _keyword_QUMARK( arg ) arg.key.to_s else raise TypeError, "Error: keyword->string expects only keyword object." end end |
#_keyword_QUMARK(arg) ⇒ Object
315 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 315 def _keyword_QUMARK( arg ) (arg.is_a? LispKeyword) end |
#_le_QUMARK(a, b) ⇒ Object
292 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 292 def _le_QUMARK( a,b ) a <= b end |
#_length(arg) ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 255 def _length( arg ) if _null_QUMARK( arg ) 0 elsif arg.is_a? Cell arg.length else raise TypeError end end |
#_list(*args) ⇒ Object
264 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 264 def _list( *args) args[0] end |
#_lt_QUMARK(a, b) ⇒ Object
291 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 291 def _lt_QUMARK( a,b ) a < b end |
#_macro_QUMARK(arg) ⇒ Object
313 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 313 def _macro_QUMARK( arg ) (LispMacro == arg.class) end |
#_macroexpand_MIMARK1(arg) ⇒ Object
341 342 343 344 345 346 347 348 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 341 def ( arg ) if _pair_QUMARK( arg ) ( 1 ) ( arg, [], [] ) else arg end end |
#_make_MIMARKkeyword(arg) ⇒ Object
459 460 461 462 463 464 465 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 459 def _make_MIMARKkeyword( arg ) if _symbol_QUMARK( arg ) or _string_QUMARK( arg ) LispKeyword.new( arg.to_s ) else raise TypeError, "Error: make-keyword expects symbol or string object." end end |
#_make_MIMARKrecord_MIMARKtype(name, field_names) ⇒ Object
524 525 526 527 528 529 530 531 532 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 524 def _make_MIMARKrecord_MIMARKtype( name, field_names ) if (name.is_a? String or _symbol_QUMARK( name )) and __PAMARKlist_QUMARK( field_names ) name = name.to_s if _symbol_QUMARK( name ) record = Nendo::Record.new( name, field_names.to_arr ) return record else raise TypeError, "Error: make-record-type requires name(string or symbol) and field(list).\n" end end |
#_make_MIMARKvalues(lst) ⇒ Object
439 440 441 442 443 444 445 446 447 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 439 def _make_MIMARKvalues( lst ) if _pair_QUMARK( lst ) LispValues.new( lst.to_arr ) elsif _null_QUMARK( lst ) LispValues.new( [] ) else raise ArgumentError, "Error: make-values expects a list argument." end end |
#_modulo(first, *rest) ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 171 def _modulo( first, *rest ) raise TypeError if not _number_QUMARK(first) rest = rest[0].to_arr __assertFlat( rest ) if 0 == rest.length 1 % first else rest.inject(first){|x,y| x%y} end end |
#_newline ⇒ Object
311 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 311 def _newline( ) print "\n" end |
#_nil_QUMARK(arg) ⇒ Object
353 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 353 def _nil_QUMARK( arg ) arg.nil? end |
#_not(arg) ⇒ Object
182 183 184 185 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 182 def _not( arg ) arg = false if Nil == arg.class not arg end |
#_null_QUMARK(arg) ⇒ Object
246 247 248 249 250 251 252 253 254 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 246 def _null_QUMARK( arg ) if Nil == arg.class true elsif Cell == arg.class arg.isNull else false end end |
#_number_QUMARK(arg) ⇒ Object
339 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 339 def _number_QUMARK( arg ) arg.is_a? Numeric end |
#_pair_QUMARK(arg) ⇒ Object
324 325 326 327 328 329 330 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 324 def _pair_QUMARK( arg ) if _null_QUMARK( arg ) false else (Cell == arg.class) end end |
#_print(arg) ⇒ Object
234 235 236 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 234 def _print( format, *rest ) print( format, *(rest[0].to_arr) ) end |
#_printf(format, *rest) ⇒ Object
238 239 240 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 238 def _printf( format, *rest ) Kernel::printf( format, *(rest[0].to_arr) ) end |
#_procedure_QUMARK(arg) ⇒ Object
312 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 312 def _procedure_QUMARK( arg ) ((Proc == arg.class) or (Method == arg.class)) end |
#_quotient(first, second) ⇒ Object
159 160 161 162 163 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 159 def _quotient( first, second ) raise TypeError if not _number_QUMARK(first) raise TypeError if not _number_QUMARK(second) (first / second.to_f).to_i end |
#_range(num, *args) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 267 def _range( num, *args ) arr = args[0].to_arr if 0 < arr.length if arr[0].is_a? Integer (0..num-1).to_a.map { |x| x + arr[0] }.to_list else raise TypeError, "Error range's start expects number." end else (0..num-1).to_a.to_list end end |
#_read(*args) ⇒ Object
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 407 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 |
#_read_MIMARKfrom_MIMARKstring(str) ⇒ Object
397 398 399 400 401 402 403 404 405 406 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 397 def _read_MIMARKfrom_MIMARKstring( str ) if not str.is_a? String raise TypeError, "Error: read-from-string expects sexp as String." else sio = StringIO.open( str ) reader = Reader.new( sio, "(string)", false ) s = reader._read s[0] end end |
#_remainder(first, second) ⇒ Object
165 166 167 168 169 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 165 def _remainder( first, second ) raise TypeError if not _number_QUMARK(first) raise TypeError if not _number_QUMARK(second) first - _quotient( first, second ) * second end |
#_require(arg) ⇒ Object
393 394 395 396 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 393 def _require( arg ) require( arg ) false end |
#_reverse(arg) ⇒ Object
265 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 265 def _reverse( arg ) arg.to_arr.reverse.to_list end |
#_set_MIMARKcar_EXMARK(cell, arg) ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 202 def _set_MIMARKcar_EXMARK( cell, arg ) if cell.is_a? Cell cell.car = arg cell else raise TypeError end end |
#_set_MIMARKcdr_EXMARK(cell, arg) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 211 def _set_MIMARKcdr_EXMARK( cell, arg ) arg = if arg.is_a? Cell _null_QUMARK( arg ) ? Nil.new : arg else arg end if cell.is_a? Cell cell.cdr = arg cell else raise TypeError end end |
#_sprintf(format, *rest) ⇒ Object
242 243 244 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 242 def _sprintf( format, *rest ) Kernel::sprintf( format, *(rest[0].to_arr) ) end |
#_string_MIMARK_GTMARKsymbol(arg) ⇒ Object
379 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 379 def _string_MIMARK_GTMARKsymbol( arg ) arg.intern end |
#_string_MIMARKjoin(lst, *args) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 381 def _string_MIMARKjoin( lst, *args ) arr = args[0].to_arr if 0 < arr.length if not arr[0].is_a? String raise TypeError, "Error: string-join's expects delimitter as String." else lst.to_a.map{ |x| x.car }.join( arr[0] ) end else lst.to_a.map{ |x| x.car }.join end end |
#_string_QUMARK(arg) ⇒ Object
340 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 340 def _string_QUMARK( arg ) arg.is_a? String end |
#_symbol_MIMARK_GTMARKstring(arg) ⇒ Object
380 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 380 def _symbol_MIMARK_GTMARKstring( arg ) arg.to_s end |
#_symbol_QUMARK(arg) ⇒ Object
314 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 314 def _symbol_QUMARK( arg ) (arg.is_a? Symbol or arg.is_a? SyntacticClosure or arg.is_a? ParsedSymbol) end |
#_syntax_QUMARK(arg) ⇒ Object
316 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 316 def _syntax_QUMARK( arg ) (arg.is_a? LispSyntax) end |
#_to_arr(arg) ⇒ Object
367 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 367 def _to_arr( arg ) _to_MIMARKarr( arg ) end |
#_to_i(arg) ⇒ Object
351 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 351 def _to_i( arg ) _to_MIMARKi( arg ) end |
#_to_list(arg) ⇒ Object
354 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 354 def _to_list( arg ) _to_MIMARKlist( arg ) end |
#_to_MIMARKarr(arg) ⇒ Object
368 369 370 371 372 373 374 375 376 377 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 368 def _to_MIMARKarr( arg ) case arg when Cell arg.to_arr when Array arg else raise TypeError end end |
#_to_MIMARKi(arg) ⇒ Object
352 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 352 def _to_MIMARKi( arg ) arg.to_i end |
#_to_MIMARKlist(arg) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 355 def _to_MIMARKlist( arg ) case arg when Enumerator arg.to_list when Array arg.to_list when Cell arg else raise TypeError end end |
#_to_MIMARKs(arg) ⇒ Object
350 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 350 def _to_MIMARKs( arg ) arg.to_s end |
#_to_s(arg) ⇒ Object
349 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 349 def _to_s( arg ) _to_MIMARKs( arg ) end |
#_uniq(arg) ⇒ Object
266 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 266 def _uniq( arg ) arg.to_arr.uniq.to_list end |
#_values_MIMARKvalues(arg) ⇒ Object
451 452 453 454 455 456 457 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 451 def _values_MIMARKvalues( arg ) if _values_QUMARK( arg ) arg.values.to_list else raise TypeError, "Error: values-values expects only LispValues object." end end |
#_values_QUMARK(arg) ⇒ Object
449 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 449 def _values_QUMARK( arg ) arg.is_a? LispValues end |
#_vector_MIMARKset_EXMARK(v, index, value) ⇒ Object
514 515 516 517 518 519 520 521 522 |
# File 'lib/nendo/ruby/builtin_functions.rb', line 514 def _vector_MIMARKset_EXMARK( v, index, value ) if !(v.is_a? Array) raise TypeError, "Error: vector-set! requires Array as argument v(Lisp's vector).\n" end if (index < 0) or (v.size <= index) raise ArgumentError, "Error: vector-set! requires index between 0 and (size-1) number.\n" end v[index] = value end |