Re:LFMs and LFSPs (Michael Vanier via PG)
by pg on Monday July 09, 2007 @12:38PM
(#33275)
If (1...10) doesn't yield a list of numbers from 1 to 10 inclusive, that's a bug in Ruby. The problem is not density. It's perfectly clear what this code example should mean.
[ Parent
| on HN ]
Sadly, no:
irb(main):001:0> (1..10).max
=> 10
irb(main):002:0> (1...10).max
=> 9
Ruby suffers from a bit of Perl-syndrome, and relies too much on magic syntax and "conventions" created by library authors. It's a nice language and all, but I still prefer Python over Ruby since Python is a simple, clean and elegant language with just a small number of elegant concepts.Python does the same thing with range:
>>> range(1,10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Leaving out the starting value starts at zero: >>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Which is like dotimes: [1]> (dotimes (i 10) (format t "~d" i))
0123456789
NIL
There's an implied "less than the supplied high value" in all cases.I'm not claiming that that example is dense code in and of itself, merely that encoding important differences in subtle ways is a by product of the LSFP way of thought. Verbose code is the opposite of clever code, so far as I can see.