rubymotionlisp 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88feeedc4e49b1ad79bfa294d7d6bc8b22900253
4
- data.tar.gz: d0ce6a144e369aa47187a93651e06c96e1f8f95d
3
+ metadata.gz: dda4c6e2e0b9e98084434161a3c0442542e51e6c
4
+ data.tar.gz: 321a515ebc17e84c7c29fca9f479d87a9b9c253d
5
5
  SHA512:
6
- metadata.gz: fd1ae7d9a5889c89fb2063b0feaf2edfdbb9e2758d3568efa1d972070063b76fbd28e6e94ccd218533712ea3134d1f64de4b29eba5de59c5b1ca0cb4137363d1
7
- data.tar.gz: 752f28753649f20785cd69da11935e4cfd17001197514d7470e7ab7e07d2dd2889ebffeed76c167ca97580b7cd6cdbd1e9320801f6d9ad83dd1e5761a5281fa9
6
+ metadata.gz: d55fb467b861a95fd5d99fd97e67e74a92e4ad39f67625679487d433f3bf475effcafc293ac9d920ac5c5141d823d8e0effbe4295c9e8e8e4e525944638c6079
7
+ data.tar.gz: 75dd34314faf4e762c90805402cf530cdbce9902d1e28bb42931342a3d5e66eee359ed0d453037811f848d0c3d4110a8a893ab78daa43822c4905e3ef3503a2a
@@ -1,8 +1,15 @@
1
1
  module Lisp
2
2
 
3
+
4
+ def self.named_let_stack
5
+ @@named_let_stack ||= Array.new
6
+ end
7
+
8
+
3
9
  class Initializer
4
10
 
5
11
  def self.initialize_global_environment
12
+ $named_let_stack = []
6
13
  Lisp::EnvironmentFrame.global.bind(Symbol.named("nil"), nil)
7
14
  end
8
15
 
@@ -248,6 +248,7 @@ module Lisp
248
248
  def evaluate(env)
249
249
  return self if empty?
250
250
  sexpr = if @car.symbol?
251
+ throw :named_let_application, @cdr.to_a.map {|a| a.evaluate(env)} if @car.eq?(Lisp.named_let_stack[-1])
251
252
  key = @car
252
253
  frame = nth(1)
253
254
  value = nth(2)
@@ -348,9 +348,9 @@ module Lisp
348
348
  end
349
349
 
350
350
 
351
- def self.let_impl(args, env)
351
+ def self.common_let_impl(args, env)
352
352
  bindings = args.car || Lisp::ConsCell.new
353
- return Lisp::Debug.process_error("let requires a list of bindings as it's firest argument", env) unless bindings.list?
353
+ return Lisp::Debug.process_error("let requires a list of bindings as it's first argument", env) unless bindings.list?
354
354
  local_frame = EnvironmentFrame.extending(env, "let")
355
355
  local_frame.previous = env
356
356
  do_let_bindings(bindings, env, local_frame)
@@ -358,6 +358,39 @@ module Lisp
358
358
  end
359
359
 
360
360
 
361
+ def self.named_let_impl(args, env)
362
+ name = args.car
363
+ bindings = args.cadr || Lisp::ConsCell.new
364
+ binding_names = bindings.to_a.map {|b| b.car}
365
+ return Lisp::Debug.process_error("named let requires a list of bindings as it's second argument", env) unless bindings.list?
366
+ body = args.cddr
367
+ local_frame = EnvironmentFrame.extending(env, "let-#{name.to_s}")
368
+ local_frame.previous = env
369
+ do_let_bindings(bindings, env, local_frame)
370
+ Lisp.named_let_stack.push(name)
371
+ while true
372
+ new_values = catch :named_let_application do
373
+ result = body.evaluate_each(local_frame)
374
+ Lisp.named_let_stack.pop
375
+ return result
376
+ end
377
+ return Lisp::Debug.process_error("named let call requires the same number of values as bindings", env) unless binding_names.length == new_values.length
378
+ binding_names.zip(new_values) do |binding_pair|
379
+ local_frame.bind_locally(binding_pair[0], binding_pair[1])
380
+ end
381
+ end
382
+ end
383
+
384
+
385
+ def self.let_impl(args, env)
386
+ if args.car.symbol?
387
+ named_let_impl(args, env)
388
+ else
389
+ common_let_impl(args, env)
390
+ end
391
+ end
392
+
393
+
361
394
  def self.letstar_impl(args, env)
362
395
  bindings = args.car || Lisp::ConsCell.new
363
396
  return Lisp::Debug.process_error("let requires a list of bindings as it's firest argument", env) unless bindings.list?
@@ -28,13 +28,37 @@ module Lisp
28
28
  end
29
29
 
30
30
 
31
+ # def self.log_eval(sexpr, env)
32
+ # end
33
+
34
+
35
+ # def self.log_result(result, env)
36
+ # end
37
+
38
+ def self.print_dashes(level)
39
+ NSLog("-" * level)
40
+ end
41
+
42
+
31
43
  def self.log_eval(sexpr, env)
44
+ if !self.eval_in_debug_repl && self.trace
45
+ depth = env.depth
46
+ NSLog("% #d: " % depth)
47
+ print_dashes(depth)
48
+ NSLog("> #{sexpr.to_s}")
49
+ end
32
50
  end
33
51
 
34
52
 
35
53
  def self.log_result(result, env)
54
+ if !self.eval_in_debug_repl && self.trace
55
+ depth = env.depth
56
+ NSLog("% #d: <" % depth)
57
+ print_dashes(depth)
58
+ NSLog(" #{result.to_s}")
59
+ end
36
60
  end
37
-
61
+
38
62
 
39
63
  end
40
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubymotionlisp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Astels