public
Description: a Scheme written in Ruby, but implemented on the bus!
Homepage: http://bus-scheme.rubyforge.org
Clone URL: git://github.com/technomancy/bus-scheme.git
Array#to_list is now recursive
technomancy (author)
Sun Mar 16 20:36:23 -0700 2008
commit  2c048169823d8a64e86824337674721bb03d00bd
tree    f1a89781fd92e599204fd9b1de7ca3f4ffb853cd
parent  d4dc1c7228d995f733a8da97f355c6625b857aba
...
 
 
 
...
1
2
3
0
@@ -0,0 +1,3 @@
0
+===
0
+===
0
+===
...
13
14
15
16
 
17
18
19
...
13
14
15
 
16
17
18
19
0
@@ -13,7 +13,7 @@ Hoe.new('bus-scheme', BusScheme::VERSION) do |p|
0
   p.email = 'technomancy@gmail.com'
0
   p.summary = 'Bus Scheme is a Scheme in Ruby, imlemented on the bus.'
0
   p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
0
- p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
0
+ p.url = 'http://bus-scheme.rubyforge.org'
0
   p.remote_rdoc_dir = ''
0
 end
0
 
...
7
8
9
10
11
12
13
 
 
14
15
16
 
17
18
 
19
20
21
...
7
8
9
 
 
 
 
10
11
12
13
 
14
15
 
16
17
18
19
0
@@ -7,15 +7,13 @@ class Array
0
   alias_method :car, :first
0
   alias_method :cdr, :rest
0
 
0
- def to_list
0
- car = self.car
0
- # TODO: make this car-recursive?
0
- # car = car.to_list if car.respond_to?(:to_list)
0
+ def to_list(recursive = false)
0
+ self[0] = first.to_list(recursive) if recursive and first.respond_to?(:to_list)
0
 
0
     if self.cdr.nil? or self.cdr.empty?
0
- BusScheme::Cons.new(car, nil)
0
+ BusScheme::Cons.new(car)
0
     else
0
- BusScheme::Cons.new(car, self.cdr.to_list)
0
+ BusScheme::Cons.new(car, self.cdr.to_list(recursive))
0
     end
0
   end
0
 
...
15
16
17
 
 
 
 
 
 
 
 
 
 
 
18
19
20
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0
@@ -15,6 +15,17 @@ module BusScheme
0
     alias_method :first, :car
0
     alias_method :rest, :cdr
0
 
0
+ def length
0
+ # TODO: actually calculate this
0
+ self.to_a.length
0
+ end
0
+
0
+ alias_method :size, :length
0
+ def last
0
+ # TODO: do this list-style
0
+ self.to_a.last
0
+ end
0
+
0
     def map(mapper)
0
       Cons.new(mapper.call(@car), @cdr ? @cdr.map(mapper) : @cdr)
0
     end
...
28
29
30
31
 
32
33
34
...
28
29
30
 
31
32
33
34
0
@@ -28,7 +28,7 @@ class Object
0
     return self
0
   end
0
 
0
- def sexp
0
+ def sexp(r = false)
0
     self
0
   end
0
   
...
7
8
9
10
 
11
12
13
...
7
8
9
 
10
11
12
13
0
@@ -7,7 +7,7 @@ module BusScheme
0
   def parse(input)
0
     @@lines = 1
0
     # TODO: should sexp it as it's being constructed, not after
0
- parse_tokens(tokenize(input).flatten).sexp
0
+ parse_tokens(tokenize(input).flatten).sexp(true)
0
   end
0
 
0
   # Turn a list of tokens into a properly-nested array
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@ class BusSchemeLambdaTest < Test::Unit::TestCase
0
   def test_simple_lambda
0
     l = eval("(lambda () (+ 1 1))")
0
     assert l.is_a?(Lambda)
0
- assert_equal [[:+.sym, 1, 1]], l.body
0
+ assert_equal [[:+.sym, 1, 1]].to_list(true), l.body
0
     assert_equal [], l.formals
0
 
0
     eval("(define foo (lambda () (+ 1 1)))")
...
170
171
172
173
 
174
175
176
...
170
171
172
 
173
174
175
176
0
@@ -170,7 +170,7 @@ class BusSchemeParserTest < Test::Unit::TestCase
0
   private
0
 
0
   def assert_parses_to(actual_string, expected)
0
- assert_equal expected.sexp, BusScheme.parse(actual_string)
0
+ assert_equal expected.sexp(true), BusScheme.parse(actual_string)
0
   end
0
 
0
   def assert_parses_equal(one, two, message = nil)

Comments

    No one has commented yet.