Re: Q: Code example in Using Perl 6 - methods and spaces.

2010-12-27 Thread Darren Duncan

Daniel Carrera wrote:

I tested the first program using the latest release of Rakudo Star.
The first program has the following:

my @sorted = @names.sort({ %sets{$_} }).sort({ %matches{$_} }).reverse;

This works correctly, but it's long and I'd rather format this line like this:

This works correctly, but I was surprised that this doesn't:

my @sorted = @names.sort({ %sets{$_} })
   .sort({ %matches{$_} })
   .reverse;

I was surprised when this didn't work. Does anyone know if this is a
bug in Rakudo, or if Perl 6 is really not supposed to have methods
separated by white space like this? The message from Rakudo was not
very informative. It just says Confused at line 28, near my @sorted.


A relevant reading would be 
http://perlcabal.org/syn/S02.html#Whitespace_and_Comments I think; what you are 
trying to do may not directly be allowed, though there may be workarounds such 
as by using unspace.


-- Darren Duncan


Re: Q: Code example in Using Perl 6 - methods and spaces.

2010-12-27 Thread Daniel Carrera
On Mon, Dec 27, 2010 at 8:37 PM, Darren Duncan dar...@darrenduncan.netwrote:

 A relevant reading would be
 http://perlcabal.org/syn/S02.html#Whitespace_and_Comments I think; what
 you are trying to do may not directly be allowed, though there may be
 workarounds such as by using unspace.


Thanks. The blacklash unspace works.

my @sorted = @names.sort({ %sets{$_} })\
   .sort({ %matches{$_} })\
   .reverse;

Though I'm a bit sad that you need that and you can't just separate methods
with spaces.

Daniel.
-- 
No trees were destroyed in the generation of this email, but a large number
of electrons were severely inconvenienced.


Re: Q: Code example in Using Perl 6 - methods and spaces.

2010-12-27 Thread Moritz Lenz
On 12/27/2010 09:12 PM, Daniel Carrera wrote:
 Thanks. The blacklash unspace works.
 
 my @sorted = @names.sort({ %sets{$_} })\
.sort({ %matches{$_} })\
.reverse;
 
 Though I'm a bit sad that you need that and you can't just separate methods
 with spaces.

But there's a good reason: .method is a term on its own, and actually
means $_.method. So if you write  @names.foo .bar, that's two terms in a
row.

You could argue that that's always a syntax error, and we could
special-case it after a method, but I think it's a bad idea. Firstly
it's an exception that makes it harder to learn the language, and
secondly disallowing two terms in a row is what enables predictive
parsing, and is very important for getting sensible syntax error messages.

Cheers,
Moritz