in reply to Re: Syntax Highlighting Editors Beware
in thread Syntax Highlighting Editors Beware

It is not Perl 6 style to write foo-bar to mean foo - bar, because there are other cases where the space is required before an infix operator. I suppose that's why it didn't bother the test suite code.

It doesn't say that - is a letter, so \w and \W are not affected.

—John

Replies are listed 'Best First'.
Re^3: Syntax Highlighting Editors Beware
by swampyankee (Parson) on Aug 11, 2008 at 02:35 UTC

    Just out of curiosity (as I've not been following Perl 6) why do some (but not all?) infix operators require spaces? I can understand the need for spaces with operators like eq, where whitespace is needed to separate the operator from the variables surrounding it, but I'm not sure why it would be needed for operators which are not characters permitted in variable names.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

      To disambiguate infix and postfix operators. The postix cannot have space before. If both exist, the infix must have space before. If there is no postfix operator of that name, then you can omit the space.

      That one concept alone allows the language to be much richer, without introducing more symbols and keywords.

      For example, .foo means call method $_.foo, and you don't call methods without using a dot at all as in C++. But it means that $xxx.foo can't have a space before the dot. You can also say @list».+foo to call all methods named foo on each item in the list. The » modifies the postfix "method call" dot, but is also used to modify infix operators.

      If you wrote your own infix:<++> operator, you could distinguish between $x++ and $x ++ ... always and without unlimited backtracking.

      Now the set of operators borrowed from C++ don't have that particular ambiguity, because it can't handle it. Thus, you're not used to having an infix ++, etc. But a lot of syntax in Perl 6 is really done with operators, including function call, dot, and of course modifiers that can go on any kind of operator.

      —John