Quoted from "Seven Deadly Sins of Introductory Programming Language 
Design" [1] by Linda McIver and Damian Conway:

    We have shown over one thousand novice programming students
    the C/C++ expression:

     "the quick brown fox" + "jumps over the lazy dog"

   and asked them what they believe the effect of the + sign is.
   Not one of them has ever suggested that the + sign is illegally
   attempting to add the address of the locations of the first two
   characters of the two literal strings.  Without exception they
   believed that the + should concatenate the two strings.

Makes perfect sense to me.  

Can we overload + in Perl 6 to work as both numeric addition
and string concatenation, depending on the type of the operand 
on the left?

I realise the answer is "probably not", given the number/string
ambiguity of Perl variables:

  my $a = 123;
  my $b = 456;
  $a + $b;     # 579 or 123456?

I quite like '_' as the string concatenation operator (so much so
that I added it to the Template Toolkit some time ago, confidently
telling people that it's what Perl 6 would use :-).  It ties in 
nicely with the 123_456 numerical style.

On the other hand, I'm not a big fan of using '~' to indicate 
string context.  The tilde (aka wobbly operator) seems much better
suited to smart matching, IMHO, being reminiscent of the "almost
equal to" operator (which I would attempt to include here if I
had the slightest clue how to make my keyboard speak Unicode).

Another option: could we quote operators to indicate string context?

  $a "+" $b

This would tie in nicely with using [ ] to indicate vectorised
operators, although I realise that particular syntax has been 
disvogued of late.

  @a [+] @b


A

[1] http://www.csse.monash.edu.au/~damian/papers/ [2]
[2] Good paper, well worth a read.  That Conway chap seems to know
    his cookies.  His name rings a bell, too...

Reply via email to