On Nov 7, 2005, at 10:06 AM, Christophe Grandsire wrote:
> If one can accept that with strings '<' means comparison while '<<'
> means concatenation, why cannot
> they accept that after the keyword 'class' '<' means subclassing  
> while '<<'
> means getting the singleton class?

I can accept it.  Semantic overloading happens all the time in
programming languages and natural languages.  It also can be
confusing during the learning process or if the overloaded definitions
are only vaguely related.  Of course once the overloaded meanings
have been internalized, it all seems much clearer than it did before.

Another Ruby example that bit me because of my C and C++ background:  
Kernel#include.
It took me a long time to get my head around the fact that #include  
is not some
sort of directive to read and interpret a file.  Its behavior isn't  
at all related
to the #include functionality of C and C++.


I was poking around to see if there was any historical debate on
overloading the left shift operator ('<<') for use with IO and then
by extension with other sorts of concatenation behavior.  I found this
interesting example:


// Demonstrate shift operators
#include <iostream>
using namespace std;

int main() {
    cout   << "5 times 2 is " << (5 << 1) << endl
          << "20 divided by 4 is " << (20 >> 2) << endl;
}

The prose around this example neglected to explain that '<<' is used
in two vastly different ways. This would be pretty difficult
to digest if you didn't already understand how the semantics of '<<' had
been overloaded.


Gary Wright