I'm only familiar with Ruby syntax, and not 100% fluent in it, but it seems to me like this kind of shortcut could make your code much less readable for not a whole lot of gain. I'm curious what the major benefit is over doing it 'the old fashioned way'.
I've very tempted to combine your work with this and then go on to define rationals and then the reals. The reals would be very interesting since it would be a sequence that takes an epsilon and gets a rational number that is close enough. It's kind of crazy to think that all these real numbers are infinite cauchy sequences.
If I define a real as function(eps) { return some_rational; } then I could define it piece_wise and say function mult_real(a,b) { return function(eps) { return a(eps/2) * b(eps/2); } }
Building the reals out of lambda calculus would be cool. I don't think however that your definition of mult_real is correct. For example if a=b=10 and eps=2, then a(eps/2) x b(eps/2) could be anything between 9x9=81 and 11x11=121, whereas you'd want it to be between 99 and 101? How to fix this?
This seems to boil down to a preference for expressions over statements. It's easier to reason about the meaning of a value than a listing of commands, and more insightful to recombine subexpressions to make values than to recombine statements to get side-effects and void.
15 comments
[ 3.2 ms ] story [ 46.1 ms ] thread(3==3).true?{'Yes'} => "Yes"
(4==4).true?{'Yes'} => nil
using this implementation:
class Object def true? yield end end
class FalseClass def true? end end
class NilClass def true? end end
It gets better.
Pairs:
Unions: Pairs combined with unions make lists: Isn't it neat how you can build everything, including conditionals, booleans, pairs and lists from functions?Note that this code was not tested in any way, so it likely contains bugs.
a --> (a,0)
-a --> (0,a)
succ((a,0)) = (a+1,0)
pred((a,0)) = (a,0+1)
I just did a construction of the integers assuming either sets or arrays. I could equally have used your list definition.
http://pastie.org/1397123 and http://news.ycombinator.com/item?id=2030649
I've very tempted to combine your work with this and then go on to define rationals and then the reals. The reals would be very interesting since it would be a sequence that takes an epsilon and gets a rational number that is close enough. It's kind of crazy to think that all these real numbers are infinite cauchy sequences.
If I define a real as function(eps) { return some_rational; } then I could define it piece_wise and say function mult_real(a,b) { return function(eps) { return a(eps/2) * b(eps/2); } }
http://news.ycombinator.com/item?id=1581830
If you aren't used to it, it looks a bit unusual (of course) but it makes for much cleaner, and therefore more maintainable, code.