On Tue, Oct 16, 2007 at 04:02:35AM +0900, Gerardo Santana G?mez Garrido wrote: > > nil has other uses besides representing nothing: it means false in a > boolean context. What purpose do you propose for nil if it isn't differentiated in behavior from false in that manner? Shouldn't we then either replace all instance of false with nil or all instances of nil with false? > > If nil > Under that logic then zero must evaluate to false, just like C and Python does. > I don't agree with that, of course. No . . . 0 would evaluate as 0 or true, while nil would evaluate as false. Similarly, "1" evaluates as "1", but "1".to_i evaluates as 1. That's the point of a method like to_i, as far as I can tell. > > Chand Perrin wrote: > > What would you expect it to return, and why would you think that should > > be the expected behavior? > > I'd expect the same behavior as FalseClass and TrueClass: undefined method. Thanks for clarifying that. That makes a certain amount of sense, though I'm not convinced it makes more sense than nil.to_i returning 0. > > Because if I want 0 would expect or send 0, not nil.to_i. > Because it doesn't make sense to me that nil, which means false also, > can be represented as zero, when zero doesn't mean false, but true. Trans made the point that eliminating to_i from the nil lineup of methods would suddenly result in a lot of ( x ? x.to_i : 0 ) being used. It seems to me that nil.to_i is convenient, makes a certain amount of logical sense, and doesn't actually introduce unexpected behavior except in pathological edge-cases. Am I missing some non-pathological, non-edge cases? > > Chad Perrin wrote: > > How about any circumstance in which one performs some kind of counting > > function in code, and operates on the number of whatever is counted, > > where no specific value is yet applied to the variable in question until > > the first item is counted? > > I don't think I understood you. Correct me plese, but I think you're talking > about an accumulator? In that case, you should start from zero, not nil. . . . -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] Marvin Minsky: "It's just incredible that a trillion-synapse computer could actually spend Saturday afternoon watching a football game."