perl6-language
[Top] [All Lists]

Closure vs Hash Parsing

To: Perl6 <perl6-language@perl.org>
Subject: Closure vs Hash Parsing
From: Jonathan Worthington <jonathan@jnthn.net>
Date: Thu, 07 Aug 2008 22:23:59 +0200
Delivered-to: mailing list perl6-all@perl.org
Delivered-to: perl6-all-poster@perl.org
Delivered-to: mailing list perl6-language@perl.org
Delivered-to: perl6-language@perl.org
List-help: <mailto:perl6-all-help@perl.org>
List-id: <perl6-all.perl.org>
List-id: <perl6-language.perl.org>
List-post: <mailto:perl6-all@perl.org>
List-subscribe: <mailto:perl6-all-subscribe@perl.org>
List-unsubscribe: <mailto:perl6-all-unsubscribe@perl.org>
Mailing-list: contact perl6-all-help@perl.org; run by ezmlm
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)
Hi,

There is in the spectests this example:

my $text  = "abc";
my %ret;
%ret = map { $_ => uc $_; }, split "", $text;
is ~%ret.kv, "a A b B c C", "=> works in a map block";

However, it seems from S06:

"|{...}| is always a block. However, if it is completely empty or consists of a single list, the first element of which is either a hash or a pair, it is executed immediately to compose a Hash object."

That this means the { $_ => uc $_; } above would end up composing a Hash object (unless the semicolon is meant to throw a spanner in the hash-composer works?) It says you can use sub to disambiguate, but

%ret = map sub { $_ => uc $_; }, split "", $text;

Doesn't work since $_ isn't an automatic parameter for a sub, like it would be in just a block (in the implementation, and if I understand correctly in the spec too).

%ret = map sub { $^a => uc $^a; }, split "", $text;

Will work, of course... But anyway, I guess either of:

* The test is wrong to expect to have that parsed as a block
* The semicolon disambiguates it - I don't see any suggestion of that in the spec, though, so if it's the case a note on this would be helpful

Thanks,

Jonathan


<Prev in Thread] Current Thread [Next in Thread>