Programming with Nothing
See the codeThis code accompanies the Ru3y Manor talk “Programming With Nothing”.
The idea is to implement some basic data structures and control flow under the constraint of only being allowed to create and call procs.
All code uses the -> syntax, so Ruby 1.9 is required.
If you are brave, the challenge branch has a set of pending specs and an empty implementation file. Can you make them all pass without breaking any of the rules? Use bundle install to set up RSpec, then just type rspec to run the specs. (To use autotest, run gem install ZenTest and then autotest.)
If you are afraid, the story branch contains a series of commits which fill out the implementation until all the specs pass.
Proc.new, Kernel.proc, Kernel.lambda or ->) and call procs (with Proc#call, Proc#[], Proc#=== or Proc#()).FOO in terms of FOO is cheating.DECREMENT is hard, so you may need to steal PRED.e can be deferred by writing it as -> x { e[x] } as long as it doesn't have any free variables called x. (This is eta-conversion.)FOO = ... FOO[...] ..., try BAR = -> f { ... f[f][...] ... }; FOO = BAR[BAR].UNSHIFT (vs. CONS) takes a list as its first (vs. last) argument. If you are upset, see the pedant branch.$ irb -Ilib -Ispec -rsupport/helpers
>> include Nothing, Helpers
=> Object
>> to_integer(from_integer(42))
=> 42
>> to_boolean(from_boolean(false))
=> false
>> to_array(from_array([true, 9, :hello]))
=> [true, 9, :hello]
>> to_array(from_array([representation_of(3), representation_of(5)])).map { |n| to_integer(n) }
=> [3, 5]
>> to_integer(ADD[TWO][THREE])
=> 5
Copyright 2011 Tom Stuart (tom@experthuman.com, @tomstuart). This is free software; see COPYING for details.
Ruby
100.0%
Programming with Nothing
See the codeThis code accompanies the Ru3y Manor talk “Programming With Nothing”.
The idea is to implement some basic data structures and control flow under the constraint of only being allowed to create and call procs.
All code uses the -> syntax, so Ruby 1.9 is required.
If you are brave, the challenge branch has a set of pending specs and an empty implementation file. Can you make them all pass without breaking any of the rules? Use bundle install to set up RSpec, then just type rspec to run the specs. (To use autotest, run gem install ZenTest and then autotest.)
If you are afraid, the story branch contains a series of commits which fill out the implementation until all the specs pass.
Proc.new, Kernel.proc, Kernel.lambda or ->) and call procs (with Proc#call, Proc#[], Proc#=== or Proc#()).FOO in terms of FOO is cheating.DECREMENT is hard, so you may need to steal PRED.e can be deferred by writing it as -> x { e[x] } as long as it doesn't have any free variables called x. (This is eta-conversion.)FOO = ... FOO[...] ..., try BAR = -> f { ... f[f][...] ... }; FOO = BAR[BAR].UNSHIFT (vs. CONS) takes a list as its first (vs. last) argument. If you are upset, see the pedant branch.$ irb -Ilib -Ispec -rsupport/helpers
>> include Nothing, Helpers
=> Object
>> to_integer(from_integer(42))
=> 42
>> to_boolean(from_boolean(false))
=> false
>> to_array(from_array([true, 9, :hello]))
=> [true, 9, :hello]
>> to_array(from_array([representation_of(3), representation_of(5)])).map { |n| to_integer(n) }
=> [3, 5]
>> to_integer(ADD[TWO][THREE])
=> 5
Copyright 2011 Tom Stuart (tom@experthuman.com, @tomstuart). This is free software; see COPYING for details.
Ruby
100.0%