perl6-language
[Top] [All Lists]

Re: Closure vs Hash Parsing

To: Carl Mäsak <cmasak@gmail.com>
Subject: Re: Closure vs Hash Parsing
From: "Patrick R. Michaud" <pmichaud@pobox.com>
Date: Sat, 9 Aug 2008 17:58:42 -0500
Cc: Perl6 <perl6-language@perl.org>
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
In-reply-to: <16d769b70808072232m58a58516ta044e23f92a619f1@mail.gmail.com>
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
References: <489B59DF.2060001@jnthn.net> <16d769b70808072232m58a58516ta044e23f92a619f1@mail.gmail.com>
User-agent: Mutt/1.5.17+20080114 (2008-01-14)
On Fri, Aug 08, 2008 at 07:32:52AM +0200, Carl Mäsak wrote:
> Jonathan (>):
> > 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).
> 
> Out of curiosity, would this work?
> 
> %ret = map -> { $_ => uc $_; }, split "", $text;

A pointy block with nothing after the arrow is a sub with zero params,
so no, this wouldn't work.  One would need something like

    %reg = map -> $_ { $_ => uc $_; }, split "", $text;

> Or this?
> 
> %ret = map { $^foo => uc $^foo; }, split "", $text;

I'm thinking S04 probably needs some clarification/updating here.
Any block that contains a (placeholder) parameter probably needs
to remain a sub, even if the block content is a comma-separated list 
starting with a pair/hash.

Pm


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