diff --git a/README.md b/README.md index 2672767..e4aa932 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Mutual Recursion -Tail call optimization for mutually (and directly) recursive functions in Ruby. +Tail call optimization for mutually (indirectly) and directly recursive functions in Ruby. -The current design uses a trampoline. However, it is implemented in a way that still allows a tail recursive function to return a Proc as its terminal value. +The current design uses a trampoline. However, it is implemented in a way that still allows a tail recursive function to easily return a Proc as its terminal value. ### examples ```ruby diff --git a/mutual_recursion.gemspec b/mutual_recursion.gemspec index dfffbf4..b8a0c82 100644 --- a/mutual_recursion.gemspec +++ b/mutual_recursion.gemspec @@ -3,10 +3,10 @@ Gem::Specification.new do |s| s.name = 'mutual_recursion' s.version = '0.0.1' - s.date = '2019-01-26' + s.date = '2019-01-27' s.summary = 'Mutual Recursion for Ruby' - s.description = 'Tail call optimization for mutually (and directly) recursive functions.' - s.authors = ['Mike'] + s.description = 'Tail call optimization for mutually and directly recursive functions.' + s.authors = ['Mike Cifelli'] s.files = ['lib/mutual_recursion.rb'] s.homepage = 'https://gitlab.com/mike-cifelli/mutual_recursion' s.license = 'MIT' diff --git a/test/mutual_recursion_test.rb b/test/mutual_recursion_test.rb index 3b10d44..6462e11 100644 --- a/test/mutual_recursion_test.rb +++ b/test/mutual_recursion_test.rb @@ -14,7 +14,7 @@ class InventoryTest < Minitest::Test tail_call { two(x, y + 1) } end - def two(x, y) + def two(x, y = 0) tail_call { one(x - 1, y) } end @@ -34,14 +34,14 @@ class InventoryTest < Minitest::Test tail_call { proc_returning(x - 1, y + 1) } end - def bad_return + def inauthentic_tail_call tail_call do Class.new do attr_reader :value, :block def initialize @value = 99 - @block = proc { 25 } + @block = proc { MutualRecursion.terminal_value(100) } end end.new end @@ -63,8 +63,10 @@ class InventoryTest < Minitest::Test end def test_mutual_tail_recursion - tail = one(50_000) - assert_equal(50_001, tail.invoke) + tail_one = one(50_000) + tail_two = two(50_000) + assert_equal(50_001, tail_one.invoke) + assert_equal(50_000, tail_two.invoke) end def test_direct_tail_recursion @@ -82,8 +84,8 @@ class InventoryTest < Minitest::Test assert_kind_of(Proc, tail.invoke) end - def test_non_tail_call_detected - tail = bad_return + def test_inauthentic_tail_call_detected + tail = inauthentic_tail_call assert_raises(MissingTailCallError) { tail.invoke } end