[E-Lang] Operators #5: Additive operators

Mark S. Miller markm@caplet.com
Mon, 09 Apr 2001 09:50:00 -0700


At 02:00 AM Monday 4/9/01, Tyler Close wrote:
>At 08:09 PM 4/6/01 -0700, Mark S. Miller wrote:
>>The other "normal" category is "Displacement Behavior", currently
>>exemplified only by characters.  In displacement behavior, when t1 and t2
>>are both elements of the type, and i is an integer,
>
>I believe here you are talking about:
>
>    'c' + 3 == 'f'
>
>Is there any reason why "displacement behaviour" shouldn't use the "<<" (ie: 
>shift) operator? So:
>
>    'c' << 3 == 'f'
>
>Doing this would allow us to use the stricter definition of "+" that many on 
>the list seem to want.

The above behavior is clearly more "addition-like" than "left-shift-like".  
The only surprise with 

    'c' + 3

is that people might not think it would work, so they wouldn't try it.  If 
they see it in someone else's code, I believe the meaning will be instantly 
clear, especially as corresponds to an existing common C idiom.  This is not 
a bad form of surprise.  OTOH, if I saw

    'c' << 3

in a C-syntax-tradition language, I would expect it to result in the 
character code gotten by shifting the character code for 'c' three bits to 
the left.  If I didn't leap to this explanation, then I would simply be at a 
loss.  This is a bad form of surprise.



Speaking of "<<", I had another bad form of surprise in a recent 
conversation with MarcS.  At the beginning of the conversation, we were both 
enthused about the proposed use of "<<" and "<<=" for manipulating lists. 
Turns out, MarcS was enthused about a plausible misunderstanding of the 
proposal.  When I said "push" he said "Wait.  Don't you mean 'pop'?"  He 
thought "<<" removed the zeroth element, rather than appended a last 
element, because only the first operation would have shifted the positions 
of all the other elements to the left.

This misunderstanding makes so much sense that I'm no longer inclined to use 
"<<" or ">>" for this kind of list manipulation without a better 
"left-shift" or "right-shift" oriented rationale.


        Cheers,
        --MarkM