develooper Front page | perl.perl6.language | Postings from April 2005

map { $_ => $_ } @foo

Thread Next
From:
Autrijus Tang
Date:
April 24, 2005 11:13
Subject:
map { $_ => $_ } @foo
Message ID:
20050424181326.GA41163@aut.dyndns.org
A while ago I posted a conflict between a block containing a pair
constructor, vs. a hash constructor:

    map { $_ => $_ } @foo;

Larry suggested that to keep it from being collapsed, we somehow
augment toplevel AST:

    map { $_ => $_; } @foo;
    map { +($_ => $_) } @foo;

But here is a new idea: Since the parser knows that the bare block is
followed by no trailing comma, how about we using it as a disambiguating
device, and define that it never collapses?

    map { $_ => $_ } @foo;  # closure
    map { $_ => $_ }, @foo; # hash

And maybe it can be extended over adverbial blocks, too:

    @foo.map:{ $_ => $_ };  # closure

Also as control structure body, just for consistency's sake:

    for @foo { $^x => $^y };

Is it a sane approach?  I have just tentatively implemented it as r2305
if people would like to experiment with this proposal.

Thanks,
/Autrijus/


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About