rubymotionlisp 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,20 +83,20 @@ end
83
83
 
84
84
 
85
85
  def self.stringp_impl(args, env)
86
- raise "string? requires 1 argument" unless args.length == 1
86
+ return Lisp::Debug.process_error("string? requires 1 argument", env) unless args.length == 1
87
87
  return Lisp::Boolean.with_value(args.car.evaluate(env).string?)
88
88
  end
89
89
 
90
90
 
91
91
  def self.make_string_impl(args, env)
92
- raise "make-string need requires at least 1 argument" unless args.length > 0
93
- raise "make-string accepts at most 2 arguments, but was passed #{args.length}" if args.length > 2
92
+ return Lisp::Debug.process_error("make-string need requires at least 1 argument", env) unless args.length > 0
93
+ return Lisp::Debug.process_error("make-string accepts at most 2 arguments, but was passed #{args.length}", env) if args.length > 2
94
94
  k_arg = args.car.evaluate(env)
95
- raise "make-string requires an integer as it's first argument." unless k_arg.integer?
95
+ return Lisp::Debug.process_error("make-string requires an integer as it's first argument.", env) unless k_arg.integer?
96
96
  k = k_arg.value
97
97
  c = if args.length == 2
98
98
  c_arg = args.cadr.evaluate(env)
99
- raise "make-string requires a character as it's second argument, but received #{c_arg}." unless c_arg.character?
99
+ return Lisp::Debug.process_error("make-string requires a character as it's second argument, but received #{c_arg}.", env) unless c_arg.character?
100
100
  c_arg.value
101
101
  else
102
102
  " "
@@ -108,7 +108,7 @@ end
108
108
  def self.string_impl(args, env)
109
109
  chars = args.to_a.map do |a|
110
110
  ea = a.evaluate(env)
111
- raise "string requires character args, but was passed #{ea}." unless ea.character?
111
+ return Lisp::Debug.process_error("string requires character args, but was passed #{ea}.", env) unless ea.character?
112
112
  ea.value
113
113
  end
114
114
  self.with_value(chars.join)
@@ -116,12 +116,12 @@ end
116
116
 
117
117
 
118
118
  def self.list_string_impl(args, env)
119
- raise "list->string requires 1 argument, but received #{args.length}" unless args.length == 1
119
+ return Lisp::Debug.process_error("list->string requires 1 argument, but received #{args.length}", env) unless args.length == 1
120
120
  list_of_chars = args.car.evaluate(env)
121
- raise "list->string requires a list argument, but received #{str_arg}" unless list_of_chars.list?
121
+ return Lisp::Debug.process_error("list->string requires a list argument, but received #{str_arg}", env) unless list_of_chars.list?
122
122
  chars = list_of_chars.to_a.map do |a|
123
123
  ea = a.evaluate(env)
124
- raise "string requires a list of characters, but it contained #{ea}." unless ea.character?
124
+ return Lisp::Debug.process_error("string requires a list of characters, but it contained #{ea}.", env) unless ea.character?
125
125
  ea.value
126
126
  end
127
127
  self.with_value(chars.join)
@@ -129,45 +129,45 @@ end
129
129
 
130
130
 
131
131
  def self.string_list_impl(args, env)
132
- raise "string->list requires 1 argument, but received #{args.length}" unless args.length == 1
132
+ return Lisp::Debug.process_error("string->list requires 1 argument, but received #{args.length}", env) unless args.length == 1
133
133
  str_arg = args.car.evaluate(env)
134
- raise "string->list requires a string argument, but received #{str_arg}" unless str_arg.string?
134
+ return Lisp::Debug.process_error("string->list requires a string argument, but received #{str_arg}", env) unless str_arg.string?
135
135
  chars = str_arg.value.each_char.map {|c| Lisp::Character.find_character_for_chr(c) }
136
136
  Lisp::ConsCell.array_to_list(chars)
137
137
  end
138
138
 
139
139
 
140
140
  def self.string_copy_impl(args, env)
141
- raise "string-copy requires 1 argument, but received #{args.length}" unless args.length == 1
141
+ return Lisp::Debug.process_error("string-copy requires 1 argument, but received #{args.length}", env) unless args.length == 1
142
142
  str_arg = args.car.evaluate(env)
143
- raise "string-copy requires a string argument, but received #{str_arg}" unless str_arg.string?
143
+ return Lisp::Debug.process_error("string-copy requires a string argument, but received #{str_arg}", env) unless str_arg.string?
144
144
  self.with_value(str_arg.value)
145
145
  end
146
146
 
147
147
 
148
148
  def self.string_length_impl(args, env)
149
- raise "string-length requires 1 argument, but received #{args.length}" unless args.length == 1
149
+ return Lisp::Debug.process_error("string-length requires 1 argument, but received #{args.length}", env) unless args.length == 1
150
150
  str_arg = args.car.evaluate(env)
151
- raise "string-length requires a string argument, but received #{str_arg}" unless str_arg.string?
151
+ return Lisp::Debug.process_error("string-length requires a string argument, but received #{str_arg}", env) unless str_arg.string?
152
152
  Lisp::Number.with_value(str_arg.value.length)
153
153
  end
154
154
 
155
155
 
156
156
  def self.string_nullp_impl(args, env)
157
- raise "string-length requires 1 argument, but received #{args.length}" unless args.length == 1
157
+ return Lisp::Debug.process_error("string-length requires 1 argument, but received #{args.length}", env) unless args.length == 1
158
158
  str_arg = args.car.evaluate(env)
159
- raise "string-length requires a string argument, but received #{str_arg}" unless str_arg.string?
159
+ return Lisp::Debug.process_error("string-length requires a string argument, but received #{str_arg}", env) unless str_arg.string?
160
160
  Lisp::Boolean.with_value(str_arg.value.length == 0)
161
161
  end
162
162
 
163
163
 
164
164
  def self.string_ref_impl(args, env)
165
- raise "string-ref requires 2 arguments, but received #{args.length}" unless args.length == 2
165
+ return Lisp::Debug.process_error("string-ref requires 2 arguments, but received #{args.length}", env) unless args.length == 2
166
166
  str_arg = args.car.evaluate(env)
167
- raise "string-ref requires a string as it's first argument, but received #{arg.car}" unless str_arg.string?
167
+ return Lisp::Debug.process_error("string-ref requires a string as it's first argument, but received #{arg.car}", env) unless str_arg.string?
168
168
  str = str_arg.value
169
169
  k_arg = args.cadr.evaluate(env)
170
- raise "string-ref requires it's second argument to be an integer, but received #{k_arg}" unless k_arg.integer?
170
+ return Lisp::Debug.process_error("string-ref requires it's second argument to be an integer, but received #{k_arg}", env) unless k_arg.integer?
171
171
  k = k_arg.value
172
172
  return Lisp::FALSE if k < 0 || k >= str.length
173
173
  Lisp::Character.find_character_for_chr(str[k])
@@ -175,16 +175,16 @@ end
175
175
 
176
176
 
177
177
  def self.string_set_impl(args, env)
178
- raise "string-set! needs 3 arguments, but received #{args.length}" unless args.length == 3
178
+ return Lisp::Debug.process_error("string-set! needs 3 arguments, but received #{args.length}", env) unless args.length == 3
179
179
  str_arg = args.car.evaluate(env)
180
- raise "string-set! needs a string as it's first argument, but received #{str_arg}" unless str_arg.string?
180
+ return Lisp::Debug.process_error("string-set! needs a string as it's first argument, but received #{str_arg}", env) unless str_arg.string?
181
181
  str = str_arg.value
182
182
  k_arg = args.cadr.evaluate(env)
183
- raise "string-set! requires an integer as it's second argument, but received #{k_arg}" unless k_arg.integer?
183
+ return Lisp::Debug.process_error("string-set! requires an integer as it's second argument, but received #{k_arg}", env) unless k_arg.integer?
184
184
  k = k_arg.value
185
185
  return Lisp::FALSE if k < 0 || k >= str.length
186
186
  replacement_arg = args.caddr.evaluate(env)
187
- raise "string-set! requires a character as it's third argument, but received #{replacement_arg}" unless replacement_arg.character?
187
+ return Lisp::Debug.process_error("string-set! requires a character as it's third argument, but received #{replacement_arg}", env) unless replacement_arg.character?
188
188
  replacement = replacement_arg.value
189
189
  str[k] = replacement
190
190
  self.with_value(str)
@@ -192,20 +192,20 @@ end
192
192
 
193
193
 
194
194
  def self.get_substring(func, str, start_index, end_index)
195
- raise "#{func} requires a string, but received #{str}" unless str.string?
195
+ return Lisp::Debug.process_error("#{func} requires a string, but received #{str}", env) unless str.string?
196
196
  s = str.value
197
- raise "#{func} requires an integer start index, but received #{start_index}" unless start_index.integer?
197
+ return Lisp::Debug.process_error("#{func} requires an integer start index, but received #{start_index}", env) unless start_index.integer?
198
198
  si = start_index.value
199
- raise "#{func} received an invalid substring start index: #{si}" if si < 0 || si > s.length
200
- raise "#{func} requires an integer end index, but received #{end_index}" unless end_index.integer?
199
+ return Lisp::Debug.process_error("#{func} received an invalid substring start index: #{si}", env) if si < 0 || si > s.length
200
+ return Lisp::Debug.process_error("#{func} requires an integer end index, but received #{end_index}", env) unless end_index.integer?
201
201
  ei = end_index.value
202
- raise "#{func} received an invalid substring end index: #{ei}" if ei < 0 || ei > s.length
202
+ return Lisp::Debug.process_error("#{func} received an invalid substring end index: #{ei}", env) if ei < 0 || ei > s.length
203
203
  s[si...ei]
204
204
  end
205
205
 
206
206
 
207
207
  def self.extract_substrings(func, args, env)
208
- raise "#{func} requires 6 arguments, but received #{args.length}" unless args.length == 6
208
+ return Lisp::Debug.process_error("#{func} requires 6 arguments, but received #{args.length}", env) unless args.length == 6
209
209
  substr1 = get_substring(func, args.nth(1).evaluate(env), args.nth(2).evaluate(env), args.nth(3).evaluate(env))
210
210
  substr2 = get_substring(func, args.nth(4).evaluate(env), args.nth(5).evaluate(env), args.nth(6).evaluate(env))
211
211
  return [substr1, substr2]
@@ -213,13 +213,13 @@ end
213
213
 
214
214
 
215
215
  def self.get_string(func, str)
216
- raise "#{func} requires a string, but received #{str}" unless str.string?
216
+ return Lisp::Debug.process_error("#{func} requires a string, but received #{str}", env) unless str.string?
217
217
  str.value
218
218
  end
219
219
 
220
220
 
221
221
  def self.extract_strings(func, args, env)
222
- raise "#{func} requires 2 arguments, but received #{args.length}" unless args.length == 2
222
+ return Lisp::Debug.process_error("#{func} requires 2 arguments, but received #{args.length}", env) unless args.length == 2
223
223
  str1 = get_string(func, args.nth(1).evaluate(env))
224
224
  str2 = get_string(func, args.nth(2).evaluate(env))
225
225
  return [str1, str2]
@@ -347,7 +347,7 @@ end
347
347
 
348
348
 
349
349
  def self.string_compare_impl(args, env)
350
- raise "string-compare requires 5 arguments, but received #{args.length}" unless args.length == 5
350
+ return Lisp::Debug.process_error("string-compare requires 5 arguments, but received #{args.length}", env) unless args.length == 5
351
351
  str1 = get_string("string-compare", args.nth(1).evaluate(env))
352
352
  str2 = get_string("string-compare", args.nth(2).evaluate(env))
353
353
  f_number = case str1 <=> str2
@@ -359,13 +359,13 @@ end
359
359
  5
360
360
  end
361
361
  f = args.nth(f_number).evaluate(env)
362
- raise "string-compare requires functions for argument #{f_number}, but received #{f}" unless f.function?
362
+ return Lisp::Debug.process_error("string-compare requires functions for argument #{f_number}, but received #{f}", env) unless f.function?
363
363
  f.apply_to(Lisp::ConsCell.cons, env)
364
364
  end
365
365
 
366
366
 
367
367
  def self.string_compare_ci_impl(args, env)
368
- raise "string-compare-ci requires 5 arguments, but received #{args.length}" unless args.length == 5
368
+ return Lisp::Debug.process_error("string-compare-ci requires 5 arguments, but received #{args.length}", env) unless args.length == 5
369
369
  str1 = get_string("string-compare-ci", args.nth(1).evaluate(env))
370
370
  str2 = get_string("string-compare-ci", args.nth(2).evaluate(env))
371
371
  f_number = case str1.downcase <=> str2.downcase
@@ -377,7 +377,7 @@ end
377
377
  5
378
378
  end
379
379
  f = args.nth(f_number).evaluate(env)
380
- raise "string-compare-ci requires functions for argument #{f_number}, but received #{f}" unless f.function?
380
+ return Lisp::Debug.process_error("string-compare-ci requires functions for argument #{f_number}, but received #{f}", env) unless f.function?
381
381
  f.apply_to(Lisp::ConsCell.cons, env)
382
382
  end
383
383
 
@@ -391,7 +391,7 @@ end
391
391
  def self.string_hash_mod_impl(args, env)
392
392
  str = get_string("string-hash-mod", args.nth(1).evaluate(env))
393
393
  k_arg = args.cadr.evaluate(env)
394
- raise "string-hash-mod requires it's second argument to be an integer, but received #{k_arg}" unless k_arg.integer?
394
+ return Lisp::Debug.process_error("string-hash-mod requires it's second argument to be an integer, but received #{k_arg}", env) unless k_arg.integer?
395
395
  k = k_arg.value
396
396
  Lisp::Number.with_value(str.hash % k)
397
397
  end
@@ -489,9 +489,9 @@ end
489
489
 
490
490
 
491
491
  def self.string_capitalize_bang_impl(args, env)
492
- raise "string-capitalize! requires 1 argument, but received #{args.length}" unless args.length == 1
492
+ return Lisp::Debug.process_error("string-capitalize! requires 1 argument, but received #{args.length}", env) unless args.length == 1
493
493
  str = args.nth(1).evaluate(env)
494
- raise "string-capitalize! requires a string, but received #{str}" unless str.string?
494
+ return Lisp::Debug.process_error("string-capitalize! requires a string, but received #{str}", env) unless str.string?
495
495
  new_chars = capitalize_string(str.value)
496
496
  new_str = ""
497
497
  new_chars.each {|c| new_str << c}
@@ -501,20 +501,20 @@ end
501
501
 
502
502
 
503
503
  def self.substring_capitalize_bang_impl(args, env)
504
- raise "substring-capitalize! requires 3 arguments, but received #{args.length}" unless args.length == 3
504
+ return Lisp::Debug.process_error("substring-capitalize! requires 3 arguments, but received #{args.length}", env) unless args.length == 3
505
505
  s = args.nth(1).evaluate(env)
506
- raise "substring-capitalize! requires a string as it's first argument, but received #{s}" unless s.string?
506
+ return Lisp::Debug.process_error("substring-capitalize! requires a string as it's first argument, but received #{s}", env) unless s.string?
507
507
  str = s.value
508
508
 
509
509
  start_index = args.nth(2).evaluate(env)
510
- raise "substring-capitalize! requires an integer start index, but received #{start_index}" unless start_index.integer?
510
+ return Lisp::Debug.process_error("substring-capitalize! requires an integer start index, but received #{start_index}", env) unless start_index.integer?
511
511
  si = start_index.value
512
- raise "substring-capitalize! received an invalid substring start index: #{si}" if si < 0 || si > str.length
512
+ return Lisp::Debug.process_error("substring-capitalize! received an invalid substring start index: #{si}", env) if si < 0 || si > str.length
513
513
 
514
514
  end_index = args.nth(3).evaluate(env)
515
- raise "substring-capitalize! requires an integer end index, but received #{end_index}" unless end_index.integer?
515
+ return Lisp::Debug.process_error("substring-capitalize! requires an integer end index, but received #{end_index}", env) unless end_index.integer?
516
516
  ei = end_index.value
517
- raise "substring-capitalize! received an invalid substring end index: #{ei}" if ei < 0 || ei > str.length
517
+ return Lisp::Debug.process_error("substring-capitalize! received an invalid substring end index: #{ei}", env) if ei < 0 || ei > str.length
518
518
 
519
519
  prefix = str[0...si]
520
520
  substr = str[si...ei]
@@ -535,29 +535,29 @@ end
535
535
 
536
536
 
537
537
  def self.string_downcase_bang_impl(args, env)
538
- raise "string-downcase! requires 1 argument, but received #{args.length}" unless args.length == 1
538
+ return Lisp::Debug.process_error("string-downcase! requires 1 argument, but received #{args.length}", env) unless args.length == 1
539
539
  str = args.nth(1).evaluate(env)
540
- raise "string-downcase! requires a string, but received #{str}" unless str.string?
540
+ return Lisp::Debug.process_error("string-downcase! requires a string, but received #{str}", env) unless str.string?
541
541
  str.set!(str.value.downcase)
542
542
  str
543
543
  end
544
544
 
545
545
 
546
546
  def self.substring_downcase_bang_impl(args, env)
547
- raise "substring-downcase! requires 3 arguments, but received #{args.length}" unless args.length == 3
547
+ return Lisp::Debug.process_error("substring-downcase! requires 3 arguments, but received #{args.length}", env) unless args.length == 3
548
548
  s = args.nth(1).evaluate(env)
549
- raise "substring-downcase! requires a string as it's first argument, but received #{s}" unless s.string?
549
+ return Lisp::Debug.process_error("substring-downcase! requires a string as it's first argument, but received #{s}", env) unless s.string?
550
550
  str = s.value
551
551
 
552
552
  start_index = args.nth(2).evaluate(env)
553
- raise "substring-downcase! requires an integer start index, but received #{start_index}" unless start_index.integer?
553
+ return Lisp::Debug.process_error("substring-downcase! requires an integer start index, but received #{start_index}", env) unless start_index.integer?
554
554
  si = start_index.value
555
- raise "substring-downcase! received an invalid substring start index: #{si}" if si < 0 || si > str.length
555
+ return Lisp::Debug.process_error("substring-downcase! received an invalid substring start index: #{si}", env) if si < 0 || si > str.length
556
556
 
557
557
  end_index = args.nth(3).evaluate(env)
558
- raise "substring-downcase! requires an integer end index, but received #{end_index}" unless end_index.integer?
558
+ return Lisp::Debug.process_error("substring-downcase! requires an integer end index, but received #{end_index}", env) unless end_index.integer?
559
559
  ei = end_index.value
560
- raise "substring-downcase! received an invalid substring end index: #{ei}" if ei < 0 || ei > str.length
560
+ return Lisp::Debug.process_error("substring-downcase! received an invalid substring end index: #{ei}", env) if ei < 0 || ei > str.length
561
561
 
562
562
  prefix = str[0...si]
563
563
  substr = str[si...ei]
@@ -578,29 +578,29 @@ end
578
578
 
579
579
 
580
580
  def self.string_upcase_bang_impl(args, env)
581
- raise "string-upcase! requires 1 argument, but received #{args.length}" unless args.length == 1
581
+ return Lisp::Debug.process_error("string-upcase! requires 1 argument, but received #{args.length}", env) unless args.length == 1
582
582
  str = args.nth(1).evaluate(env)
583
- raise "string-upcase! requires a string, but received #{str}" unless str.string?
583
+ return Lisp::Debug.process_error("string-upcase! requires a string, but received #{str}", env) unless str.string?
584
584
  str.set!(str.value.upcase)
585
585
  str
586
586
  end
587
587
 
588
588
 
589
589
  def self.substring_upcase_bang_impl(args, env)
590
- raise "substring-upcase! requires 3 arguments, but received #{args.length}" unless args.length == 3
590
+ return Lisp::Debug.process_error("substring-upcase! requires 3 arguments, but received #{args.length}", env) unless args.length == 3
591
591
  s = args.nth(1).evaluate(env)
592
- raise "substring-upcase! requires a string as it's first argument, but received #{s}" unless s.string?
592
+ return Lisp::Debug.process_error("substring-upcase! requires a string as it's first argument, but received #{s}", env) unless s.string?
593
593
  str = s.value
594
594
 
595
595
  start_index = args.nth(2).evaluate(env)
596
- raise "substring-upcase! requires an integer start index, but received #{start_index}" unless start_index.integer?
596
+ return Lisp::Debug.process_error("substring-upcase! requires an integer start index, but received #{start_index}", env) unless start_index.integer?
597
597
  si = start_index.value
598
- raise "substring-upcase! received an invalid substring start index: #{si}" if si < 0 || si > str.length
598
+ return Lisp::Debug.process_error("substring-upcase! received an invalid substring start index: #{si}", env) if si < 0 || si > str.length
599
599
 
600
600
  end_index = args.nth(3).evaluate(env)
601
- raise "substring-upcase! requires an integer end index, but received #{end_index}" unless end_index.integer?
601
+ return Lisp::Debug.process_error("substring-upcase! requires an integer end index, but received #{end_index}", env) unless end_index.integer?
602
602
  ei = end_index.value
603
- raise "substring-upcase! received an invalid substring end index: #{ei}" if ei < 0 || ei > str.length
603
+ return Lisp::Debug.process_error("substring-upcase! received an invalid substring end index: #{ei}", env) if ei < 0 || ei > str.length
604
604
 
605
605
  prefix = str[0...si]
606
606
  substr = str[si...ei]
@@ -617,7 +617,7 @@ end
617
617
  def self.string_append_impl(args, env)
618
618
  strings = args.to_a.map do |a|
619
619
  s = a.evaluate(env)
620
- raise "string-append requires strings, but received #{s}" unless s.string?
620
+ return Lisp::Debug.process_error("string-append requires strings, but received #{s}", env) unless s.string?
621
621
  s.value
622
622
  end
623
623
 
@@ -632,49 +632,49 @@ end
632
632
 
633
633
 
634
634
  def self.string_head_impl(args, env)
635
- raise "string-head requires 2 arguments, but received #{args.length}" unless args.length == 2
635
+ return Lisp::Debug.process_error("string-head requires 2 arguments, but received #{args.length}", env) unless args.length == 2
636
636
  s = args.nth(1).evaluate(env)
637
- raise "string-head requires a string as it's first argument, but received #{s}" unless s.string?
637
+ return Lisp::Debug.process_error("string-head requires a string as it's first argument, but received #{s}", env) unless s.string?
638
638
  str = s.value
639
639
 
640
640
  end_index = args.nth(2).evaluate(env)
641
- raise "string-head requires an integer end index, but received #{end_index}" unless end_index.integer?
641
+ return Lisp::Debug.process_error("string-head requires an integer end index, but received #{end_index}", env) unless end_index.integer?
642
642
  ei = end_index.value
643
- raise "string-head received an invalid end index: #{ei}" if ei < 0 || ei > str.length
643
+ return Lisp::Debug.process_error("string-head received an invalid end index: #{ei}", env) if ei < 0 || ei > str.length
644
644
 
645
645
  self.with_value(str[0...ei])
646
646
  end
647
647
 
648
648
 
649
649
  def self.string_tail_impl(args, env)
650
- raise "string-tail requires 2 arguments, but received #{args.length}" unless args.length == 2
650
+ return Lisp::Debug.process_error("string-tail requires 2 arguments, but received #{args.length}", env) unless args.length == 2
651
651
  s = args.nth(1).evaluate(env)
652
- raise "string-tail requires a string as it's first argument, but received #{s}" unless s.string?
652
+ return Lisp::Debug.process_error("string-tail requires a string as it's first argument, but received #{s}", env) unless s.string?
653
653
  str = s.value
654
654
 
655
655
  start_index = args.nth(2).evaluate(env)
656
- raise "string-tail requires an integer start index, but received #{start_index}" unless start_index.integer?
656
+ return Lisp::Debug.process_error("string-tail requires an integer start index, but received #{start_index}", env) unless start_index.integer?
657
657
  si = start_index.value
658
- raise "string-tail received an invalid end index: #{si}" if si < 0 || si > str.length
658
+ return Lisp::Debug.process_error("string-tail received an invalid end index: #{si}", env) if si < 0 || si > str.length
659
659
 
660
660
  self.with_value(str[si..-1])
661
661
  end
662
662
 
663
663
 
664
664
  def self.string_pad_left_impl(args, env)
665
- raise "string-pad-left requires 2 or 3 arguments, but received #{args.length}" unless args.length == 2 || args.length == 3
665
+ return Lisp::Debug.process_error("string-pad-left requires 2 or 3 arguments, but received #{args.length}", env) unless args.length == 2 || args.length == 3
666
666
  s = args.nth(1).evaluate(env)
667
- raise "string-pad-left requires a string as it's first argument, but received #{s}" unless s.string?
667
+ return Lisp::Debug.process_error("string-pad-left requires a string as it's first argument, but received #{s}", env) unless s.string?
668
668
  str = s.value
669
669
 
670
670
  size_arg = args.nth(2).evaluate(env)
671
- raise "string-pad-left requires an integer size, but received #{size_arg}" unless size_arg.integer?
671
+ return Lisp::Debug.process_error("string-pad-left requires an integer size, but received #{size_arg}", env) unless size_arg.integer?
672
672
  size = size_arg.value
673
- raise "string-pad-left received an invalid size: #{size}" if size < 0
673
+ return Lisp::Debug.process_error("string-pad-left received an invalid size: #{size}", env) if size < 0
674
674
 
675
675
  padding_char = if args.length == 3
676
676
  ch_arg = args.nth(3).evaluate(env)
677
- raise "string-pad-left requires a character pad, but received #{ch_arg}" unless ch_arg.character?
677
+ return Lisp::Debug.process_error("string-pad-left requires a character pad, but received #{ch_arg}", env) unless ch_arg.character?
678
678
  ch_arg.value
679
679
  else
680
680
  " "
@@ -4,13 +4,14 @@ module Lisp
4
4
 
5
5
  def self.register
6
6
  Primitive.register("sleep") {|args, env| Lisp::System.sleep_impl(args, env) }
7
+ Primitive.register("quit") {|args, env| exit() }
7
8
  end
8
9
 
9
10
 
10
11
  def self.sleep_impl(args, env)
11
- raise "sleep needs 1 argument" if args.length != 1
12
+ return Lisp::Debug.process_error("sleep needs 1 argument", env) if args.length != 1
12
13
  arg = args.car.evaluate(env)
13
- raise "sleep needs a numeric argument" unless arg.number?
14
+ return Lisp::Debug.process_error("sleep needs a numeric argument", env) unless arg.number?
14
15
  sleep(arg.value)
15
16
  end
16
17
 
@@ -11,7 +11,7 @@ module Lisp
11
11
  end
12
12
 
13
13
  def self.describe_impl(args, env)
14
- raise "First arg to describe must be a string or symbol" if !args.car.symbol? && !args.car.string?
14
+ return Lisp::Debug.process_error("First arg to describe must be a string or symbol", env) if !args.car.symbol? && !args.car.string?
15
15
  return if args.cdr.nil?
16
16
  puts
17
17
  puts " #{args.car.to_s}"
@@ -68,7 +68,7 @@ module Lisp
68
68
  when 2
69
69
  self.binary_check(name, args.car, args.cadr, env, inverted)
70
70
  else
71
- raise "check takes 1 or 2 arguments, received #{args.length}"
71
+ return Lisp::Debug.process_error("check takes 1 or 2 arguments, received #{args.length}", env)
72
72
  end)
73
73
  end
74
74
 
@@ -79,7 +79,7 @@ module Lisp
79
79
 
80
80
 
81
81
  def self.check_star_impl(args, env)
82
- raise "check* needs 2 arguments, received #{args.length}" if args.length != 2
82
+ return Lisp::Debug.process_error("check* needs 2 arguments, received #{args.length}", env) if args.length != 2
83
83
  @@number_of_tests += 1
84
84
  print " (check* #{args.car.print_string} #{args.cadr.print_string}) - "
85
85
 
@@ -7,50 +7,52 @@ module Lisp
7
7
  Primitive.register("pair?") {|args, env| Lisp::TypeChecks::typep_impl("pair?", :pair, args, env) }
8
8
  Primitive.register("symbol?") {|args, env| Lisp::TypeChecks::typep_impl("symbol?", :symbol, args, env) }
9
9
  Primitive.register("number?") {|args, env| Lisp::TypeChecks::typep_impl("number?", :number, args, env) }
10
- Primitive.register("integer?") {|args, env| Lisp::TypeChecks::integerp_impl(args, env) }
11
- Primitive.register("float?") {|args, env| Lisp::TypeChecks::floatp_impl(args, env) }
10
+ Primitive.register("integer?") {|args, env| Lisp::TypeChecks::integerp_impl(args, env) }
11
+ Primitive.register("float?") {|args, env| Lisp::TypeChecks::floatp_impl(args, env) }
12
12
  Primitive.register("function?") {|args, env| Lisp::TypeChecks::functionp_impl(args, env) }
13
13
 
14
14
  Primitive.register("nil?") {|args, env| Lisp::TypeChecks::nilp_impl(args, env) }
15
+ Primitive.register("null?") {|args, env| Lisp::TypeChecks::nilp_impl(args, env) }
15
16
  Primitive.register("not-nil?") {|args, env| Lisp::TypeChecks::not_nilp_impl(args, env) }
17
+ Primitive.register("not-null?") {|args, env| Lisp::TypeChecks::not_nilp_impl(args, env) }
16
18
  end
17
19
 
18
20
 
19
21
  def self.typep_impl(name, sym, args, env)
20
- raise "#{name} needs 1 argument" unless args.length == 1
22
+ return Lisp::Debug.process_error("#{name} needs 1 argument", env) unless args.length == 1
21
23
  return Lisp::Boolean.with_value(args.car.evaluate(env).type == sym)
22
24
  end
23
25
 
24
26
 
25
27
  def self.integerp_impl(args, env)
26
- raise "integer? needs 1 argument" unless args.length == 1
28
+ return Lisp::Debug.process_error("integer? needs 1 argument", env) unless args.length == 1
27
29
  val = args.car.evaluate(env)
28
30
  return Lisp::Boolean.with_value(val.type == :number && val.integer?)
29
31
  end
30
32
 
31
33
 
32
34
  def self.floatp_impl(args, env)
33
- raise "float? needs 1 argument" unless args.length == 1
35
+ return Lisp::Debug.process_error("float? needs 1 argument", env) unless args.length == 1
34
36
  val = args.car.evaluate(env)
35
37
  return Lisp::Boolean.with_value(val.type == :number && val.float?)
36
38
  end
37
39
 
38
40
 
39
41
  def self.functionp_impl(args, env)
40
- raise "function? needs 1 argument" unless args.length == 1
42
+ return Lisp::Debug.process_error("function? needs 1 argument", env) unless args.length == 1
41
43
  val = args.car.evaluate(env)
42
44
  return Lisp::Boolean.with_value(val.type == :function || val.type == :primitive)
43
45
  end
44
46
 
45
47
 
46
48
  def self.nilp_impl(args, env)
47
- raise "nil? needs 1 argument" unless args.length == 1
49
+ return Lisp::Debug.process_error("nil? needs 1 argument", env) unless args.length == 1
48
50
  return Lisp::Boolean.with_value(args.car.evaluate(env).nil?)
49
51
  end
50
52
 
51
53
 
52
54
  def self.not_nilp_impl(args, env)
53
- raise "not-nil? needs 1 argument" unless args.length == 1
55
+ return Lisp::Debug.process_error("not-nil? needs 1 argument", env) unless args.length == 1
54
56
  return Lisp::Boolean.with_value(!args.car.evaluate(env).nil?)
55
57
  end
56
58