On Thu, Nov 14, 2002 at 09:10:07PM +0000, Richard Proctor wrote:
: On Thu 14 Nov, Michael G Schwern wrote:
: > On Thu, Nov 14, 2002 at 12:19:47PM +0000, Andy Wardley wrote:
: > > 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?
: 
: There have been times when I have wondered if string concatination could be
: done without any operator at all.  Simply the placement of two things
: next to each other as in $foo $bar or $foo$bar would silently concatenate
: them.  But then I feel there are some deep horrors and ambiguities that
: I have failed to spot...

Yes, and it has little to do with indirect objects.  The Perl parser
differentiates many operators by whether it is expecting an operator
or a term, and *all* of those would be ambiguous if there were a
null operator.  You can't even tell whether a + is unary or binary...

Sigh.  I've said this any number of times, but it never seems to
sink in.  Perl is so slick on this point that people doen't realize
how much of this is happening already in Perl 5:

    Char        Term            Operator
    %           hash            mod
    &           sub             "and"
    *           glob            multiply, exponentiate
    -           negate          subtract
    +           noop            add
    <           input, heredoc  less than, left shift...
    .           number          concatenation
    /           regex           division
    ?           regex           conditional

Perl 6 will do things differently, but the fact remains that we can't
have a juxtapositional operator in Perl, ever.  The only place Perl 5
tries to get away with it is with indirect objects, and it's a mess,
and only works as well as it does because indirect objects aren't
general expressions.  As it is, it has to do weird lookahead stuff like
distinguishing

    print $x +1;

from

    print $x + 1;

We're trying to avoid that kind of evil in Perl 6.  We're going for
other evils this time...

Larry

Reply via email to