Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Array#to_list is now recursive

  • Loading branch information...
commit 2c048169823d8a64e86824337674721bb03d00bd 1 parent d4dc1c7
@technomancy authored
View
3  History.txt
@@ -0,0 +1,3 @@
+===
+===
+===
View
2  Rakefile
@@ -13,7 +13,7 @@ Hoe.new('bus-scheme', BusScheme::VERSION) do |p|
p.email = 'technomancy@gmail.com'
p.summary = 'Bus Scheme is a Scheme in Ruby, imlemented on the bus.'
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
- p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
+ p.url = 'http://bus-scheme.rubyforge.org'
p.remote_rdoc_dir = ''
end
View
10 lib/array_extensions.rb
@@ -7,15 +7,13 @@ def rest
alias_method :car, :first
alias_method :cdr, :rest
- def to_list
- car = self.car
- # TODO: make this car-recursive?
- # car = car.to_list if car.respond_to?(:to_list)
+ def to_list(recursive = false)
+ self[0] = first.to_list(recursive) if recursive and first.respond_to?(:to_list)
if self.cdr.nil? or self.cdr.empty?
- BusScheme::Cons.new(car, nil)
+ BusScheme::Cons.new(car)
else
- BusScheme::Cons.new(car, self.cdr.to_list)
+ BusScheme::Cons.new(car, self.cdr.to_list(recursive))
end
end
View
11 lib/cons.rb
@@ -15,6 +15,17 @@ def ==(other)
alias_method :first, :car
alias_method :rest, :cdr
+ def length
+ # TODO: actually calculate this
+ self.to_a.length
+ end
+
+ alias_method :size, :length
+ def last
+ # TODO: do this list-style
+ self.to_a.last
+ end
+
def map(mapper)
Cons.new(mapper.call(@car), @cdr ? @cdr.map(mapper) : @cdr)
end
View
2  lib/object_extensions.rb
@@ -28,7 +28,7 @@ def affect
return self
end
- def sexp
+ def sexp(r = false)
self
end
View
2  lib/parser.rb
@@ -7,7 +7,7 @@ module BusScheme
def parse(input)
@@lines = 1
# TODO: should sexp it as it's being constructed, not after
- parse_tokens(tokenize(input).flatten).sexp
+ parse_tokens(tokenize(input).flatten).sexp(true)
end
# Turn a list of tokens into a properly-nested array
View
2  test/test_lambda.rb
@@ -5,7 +5,7 @@ class BusSchemeLambdaTest < Test::Unit::TestCase
def test_simple_lambda
l = eval("(lambda () (+ 1 1))")
assert l.is_a?(Lambda)
- assert_equal [[:+.sym, 1, 1]], l.body
+ assert_equal [[:+.sym, 1, 1]].to_list(true), l.body
assert_equal [], l.formals
eval("(define foo (lambda () (+ 1 1)))")
View
2  test/test_parser.rb
@@ -170,7 +170,7 @@ def test_parser_saves_file_info
private
def assert_parses_to(actual_string, expected)
- assert_equal expected.sexp, BusScheme.parse(actual_string)
+ assert_equal expected.sexp(true), BusScheme.parse(actual_string)
end
def assert_parses_equal(one, two, message = nil)
Please sign in to comment.
Something went wrong with that request. Please try again.