Permalink
Browse files

Implement TO_STRING for natural numbers

  • Loading branch information...
1 parent 97ed146 commit 096db614dadf5a084d3a8f3226bd100df07df648 @tomstuart committed Oct 22, 2011
Showing with 3 additions and 2 deletions.
  1. +2 −1 lib/nothing.rb
  2. +1 −1 spec/nothing_spec.rb
View
3 lib/nothing.rb
@@ -75,7 +75,8 @@ module Nothing
TEN = INCREMENT[MULTIPLY[THREE][THREE]]
RADIX = TEN
TO_DIGITS = Z[-> f { -> n { PUSH[IF[IS_LESS_OR_EQUAL[n][DECREMENT[RADIX]]][EMPTY][ -> _ { f[DIV[n][RADIX]][_] } ]][MOD[n][RADIX]] } }]
- # TO_STRING =
+ TO_CHAR = -> n { n } # assume string encoding where 0 encodes '0', 1 encodes '1' etc
+ TO_STRING = -> n { MAP[TO_DIGITS[n]][TO_CHAR] }
# FizzBuzz
View
2 spec/nothing_spec.rb
@@ -41,7 +41,7 @@
end
context 'with strings' do
- specify { pending { TO_STRING[representation_of 42].should represent '42' } }
+ specify { TO_STRING[representation_of 42].should represent '42' }
end
end

0 comments on commit 096db61

Please sign in to comment.