in reply to Syntax Highlighting Editors Beware

Can't say I'm a fan of this change. This could permit some slightly confusing code, like:

# any needed definitions, prototypes, etc... sub bar { return 100; } sub foo { 50;} sub foo-bar { return rand(50); } if (foo - bar != foo-bar) { print "Haha!\n"; }
Ah, well, I've not been following Perl 6 developments, so I shouldn't be overly critical, but I can also see this as making it less than straightforward to convert a few Perl 5 scripts which rely on regex including the /\w/ or /\W/ meta-characters to Perl 6.


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

Replies are listed 'Best First'.
Re^2: Syntax Highlighting Editors Beware
by John M. Dlugosz (Monsignor) on Aug 10, 2008 at 04:34 UTC
    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

      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