Message from discussion
map { $_ => $_ } @foo
Newsgroups: perl.perl6.language
Path: g2news1.google.com!news3.google.com!newsfeed.stanford.edu!nntp.perl.org
Return-Path: <la...@london.wall.org>
Mailing-List: contact perl6-language-h...@perl.org; run by ezmlm
Delivered-To: mailing list perl6-langu...@perl.org
Received: (qmail 26968 invoked from network); 25 Apr 2005 01:50:15 -0000
Received: from x1a.develooper.com (HELO x1.develooper.com) (216.52.237.111)
by lists.develooper.com with SMTP; 25 Apr 2005 01:50:15 -0000
Received: (qmail 24031 invoked by uid 225); 25 Apr 2005 01:50:15 -0000
Delivered-To: perl6-langu...@perl.org
Received: (qmail 24023 invoked by alias); 25 Apr 2005 01:50:14 -0000
X-Spam-Status: No, hits=-2.6 required=8.0
tests=BAYES_00
X-Spam-Check-By: la.mx.develooper.com
Received-SPF: neutral (x1.develooper.com: local policy)
Received: from ylpvm15-ext.prodigy.net (HELO ylpvm15.prodigy.net) (207.115.57.46)
by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Sun, 24 Apr 2005 18:50:09 -0700
Received: from pimout1-ext.prodigy.net (pimout1-ext.prodigy.net [207.115.63.77])
by ylpvm15.prodigy.net (8.12.10 outbound/8.12.10) with ESMTP id j3P1kDNA018522
for <perl6-langu...@perl.org>; Sun, 24 Apr 2005 21:46:13 -0400
X-ORBL: [64.160.46.45]
Received: from wall.org (adsl-64-160-46-45.dsl.snfc21.pacbell.net [64.160.46.45])
by pimout1-ext.prodigy.net (8.12.10 milter /8.12.10) with ESMTP id j3P1o4YT177660
for <perl6-langu...@perl.org>; Sun, 24 Apr 2005 21:50:04 -0400
Received: from london.wall.org (localhost.localdomain [127.0.0.1])
by wall.org (8.13.1/8.12.11) with ESMTP id j3P1o31T008851
for <perl6-langu...@perl.org>; Sun, 24 Apr 2005 18:50:03 -0700
Received: (from larry@localhost)
by london.wall.org (8.13.1/8.13.1/Submit) id j3P1o3W4008846
for perl6-langu...@perl.org; Sun, 24 Apr 2005 18:50:03 -0700
Date: Sun, 24 Apr 2005 18:50:03 -0700
To: perl6-langu...@perl.org
Subject: Re: map { $_ => $_ } @foo
Message-ID: <20050425015002.GA8711@wall.org>
Mail-Followup-To: perl6-langu...@perl.org
References: <20050424181326.GA41163@aut.dyndns.org> <20050424233904.GA5718@wall.org> <p06210201be91f145f2eb@[192.168.1.101]>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <p06210201be91f145f2eb@[192.168.1.101]>
User-Agent: Mutt/1.4.1i
Approved: n...@nntp.perl.org
From: la...@wall.org (Larry Wall)
On Sun, Apr 24, 2005 at 06:14:35PM -0700, Darren Duncan wrote:
: At 4:39 PM -0700 4/24/05, Larry Wall wrote:
: >On Mon, Apr 25, 2005 at 02:13:26AM +0800, Autrijus Tang wrote:
: >: A while ago I posted a conflict between a block containing a pair
: >: constructor, vs. a hash constructor:
: >:
: >: map { $_ => $_ } @foo;
: >
: >: And maybe it can be extended over adverbial blocks, too:
: >:
: >: @foo.map:{ $_ => $_ }; # closure
:
: Why not just always use the ':' when you are giving a block. The
: block is essentially an adverb for a map|grep|sort anyway. Whereas,
: no ':' means its a hash-ref. (Presumably each of map|grep|sort will
: have a reasonable default adverb if no ':{}' is given.)
There are lots of blocks that shouldn't take colons.
: >I really think for clarity it has to be disambiguated by either
: >something syntactic on the front or something semantic at the top level.
:
: I agree. See my previous paragraph for an example.
:
: >I still
: >kinda like the rule that it's a hash if the top-level looks like some
: >kind of list of pairs. It optimizes for the common case.
:
: I agree.
:
: >Closures
: >returning pairs are a rarity.
: >Larry
:
: This is beside the point but ...
:
: Perhaps one of the new Perl 6 features makes this unnecessary, but I
: often found myself doing just that when I wanted an effective method
: to test multiple times if an element is in an array, like this:
:
: my %foo = map:{ ( $_ => 1 ) } @bar;
: if( %foo{'abc'} ) ...
: if( %foo{'def'} ) ...
: if( %foo{'zrs'} ) ...
:
: That closure is returning a pair for each array element.
How 'bout:
%foo{@bar} »=« 1;
That seems a lot clearer to me. If you don't like hyper, how about
%foo{@bar} = (1..2:by(0));
:-)
Larry