Today I put in the finishing touches to predictive parser, with support for "$x .= foo" and "foo.bar". In both cases, whitespace is now very important:
$x .= foo # $x .= $x.foo
$x .=(foo()) # same thing
$x .=(foo) # same thing
$x.=(foo) # $x.postfix:<=>(foo())
There is no built-in Perl 6 classes with the postfix:<=> method, so the last one is probably an error. Another example:
foo.bar; # foo().bar()
foo.bar(); # same thing
foo .bar; # foo($_.bar())
That is surely the correct behaviour, but my brain (too used to backtracking dwimmy parsing) still need some time to adjust from the change. The test files, too, needs some adjusting: Of the 630 test files, 76 are still failing parsing -- usually, it's a missing whitespace here or there, but there may still be some ambiguities hidden in the corner. Helps welcome to triage those tests! If you'd like to help, look at this smoke test report, grep for " 0.00%" (with the space), run "./pugs -Iblib6/lib t/path/to/test.t", and try to diagnose the error.
In other news, aufrank++ started to re-read S06: Subroutines, in order to start working on a Rules-based parser for the full signature syntax, complete with the not-yet-supported features such as array/hash/structural unpacking. Once that grammar is in place, we can use scw++'s work to use it as part of Pugs's Parsec parser, and also pack it up into a Module::Compile-based bridge to Data::Bind, to provide a modern successor to the highly impressive Perl6::Bindings for Perl 5. Yay!
Ack. So where in P5 you say
in P6 you’d have to say the following?
(Notice the placement of dots vs arrows.)
I don’t like that any more than I like it when Ruby makes me do that… hopefully, `given` combined with the shortcut for invoking methods on the topic will mostly remove the need for method chaining.
Posted by: Aristotle Pagaltzis | 2006.05.01 at 06:12 AM
Aristotle: Actually, you'd need to use the "long dot" form:
That is, "\" and "." separated by optional whitespace is an alternate spelling of the "." form. This hopefully provides sufficient visual clue on both sides as to not confuse people from either camp. :-)
Posted by: Audrey T | 2006.05.01 at 04:45 PM
I don’t know if I like where this is going… does this mean that
is also wrong, and
is necessary instead?
I have to say, sometimes I can really feel Abigail. :-(
Posted by: Aristotle Pagaltzis | 2006.05.03 at 03:23 AM
Right, that is the case indeed. And yes, I agree with your feeling.
However, the Rubyish alternative of allowing "dangling" method calls:
Really looks no cleaner to me...
Posted by: Audrey T | 2006.05.03 at 09:27 AM
I don’t like that either (and said so in the other comment). I wish it was possible to arrange the dots like the arrows in Perl 5:
If that’s not possible I’m really hoping I can just rely on topicalisation instead…
Posted by: Aristotle Pagaltzis | 2006.05.03 at 10:04 AM
of course, those mean different things:
((foo.bar).baz).quux;
versus
foo.bar;
foo.baz;
foo.quux;
as a method call doesn't always return its invocant (nor would you always want it to).
Posted by: spinclad | 2006.05.05 at 03:42 PM
They can mean different things. However, because Perl 5 does not have a syntactic shortcut for “$_->”, it is common practice to return the invocant from a method where there’s not something useful to return, so that you can chain method calls on the same invocant.
If such chains do mean something different in a lot of your code, that most likely just means the code is hard to read…
Posted by: Aristotle Pagaltzis | 2006.05.07 at 04:07 AM
well, half (say) of the method calls i make are accessors, which want to return a piece or aspect or acquaintance of their invocant, and are especially useful in chains.
in any case, the idiom for stacked chaining now has to use whatever form long dot has (finally?) taken... if you can come up with a better form that will bear the design pressures on this new language, please speak up; i imagine there isn't anyone that's overjoyed with the latest syntax. it's meant to suggest '\' line continuations, so makes some sense to me, but still looks odd and rather ugly.
Posted by: spinclad | 2006.05.07 at 06:29 AM