On Jun 10, 2007, at 6:35 AM, Robert Klemme wrote:

> A funny (and readable) way to test collection sizes just occurred  
> to me:
>
> irb(main):001:0> class Integer
> irb(main):002:1>   def elements
> irb(main):003:2>     cond = lambda {|enum| self == enum.size}
> irb(main):004:2>     class <<cond
> irb(main):005:3>       alias :=== :call
> irb(main):006:3>     end
> irb(main):007:2>     cond
> irb(main):008:2>   end
> irb(main):009:1> end
> => nil
> irb(main):010:0> case [1,2,3]
> irb(main):011:1> when 3.elements
> irb(main):012:1>   puts "three!"
> irb(main):013:1> when 5.elements
> irb(main):014:1>   puts "too much!"
> irb(main):015:1> else
> irb(main):016:1*   puts "else"
> irb(main):017:1> end
> three!
> => nil
>
> :-)

I admit this is very clever. But doesn't the user pay a rather high  
runtime cost in return for the coder's enjoying a small dollop of  
syntactic sugar? Integer#elements is a rather expensive function for  
what it delivers. Does no one recall what the late Alan Perlis wrote  
in 1982 [*]:

     A LISP programmer knows the value of everything, but the cost of  
nothing.

Should Ruby programmers vie for the same notoriety?

I realize you were only having a little fun and sharing your fun with  
the mailing list. But when others start proposing an RCR along these  
lines I get scared.

Regards, Morton

[*] No. 55 in <http://www.cs.yale.edu/quotes.html>.