Re: idiom for filling a counting hash

2004-05-18 Thread Juerd
Uri Guttman skribis 2004-05-19 0:08 (-0400): > J> 1;0 [EMAIL PROTECTED]:~$ perl -MBenchmark=cmpthese -e'my @foo = (1..16, > J> 1..10); cmpthese -1, { a => sub { my %foo; $foo{$_}++ for @foo; }, i > J> b => sub { my %foo; $_++ for @[EMAIL PROTECTED]; } }' > J> Rate a

Re: idiom for filling a counting hash

2004-05-18 Thread Uri Guttman
> "J" == Juerd <[EMAIL PROTECTED]> writes: J> John Williams skribis 2004-05-18 16:07 (-0600): >> >$a{$_}++ for @a; >> [EMAIL PROTECTED]; J> That's not a bad idea, even in Perl 5: J> 1;0 [EMAIL PROTECTED]:~$ perl -MBenchmark=cmpthese -e'my @foo = (1..16, J> 1..10); cm

Re: idiom for filling a counting hash

2004-05-18 Thread Damian Conway
Austin Hastings asked: Junctions are value, not lvalues. Why not bundle lvalues together? Because, although this would mean what it says: all($x, $y, $z)++; None of these would: any($x, $y, $z)++; one($x, $y, $z)++; none($x, $y, $z)++; We're trying to avoid intr

Re: idiom for filling a counting hash

2004-05-18 Thread Damian Conway
Luke asked: Er, did the hyper operator's direction flip? I thought it was: ++Â [EMAIL PROTECTED]; My bad. 'Tis indeed. Damian

Re: idiom for filling a counting hash

2004-05-18 Thread John Macdonald
On Tue, May 18, 2004 at 11:14:30PM +0200, Stéphane Payrard wrote: > I thought overloading the += operator > >%a += @a; There's been lots of discussion of this, but: > Probably that operator should be smart enough to be fed with > a mixed list of array and hashes as well: > > %a += ( @a, %

Re: idiom for filling a counting hash

2004-05-18 Thread Larry Wall
On Tue, May 18, 2004 at 06:32:28PM -0600, Luke Palmer wrote: : Damian Conway writes: : > Austin Hastings wrote: : > : > >Hmm. For junctions I was thinking: : > > : > > ++ all([EMAIL PROTECTED]); : > > : > >Which is almost readable. : > : > But unfortunately not correct. Junctions are value, not

Re: idiom for filling a counting hash

2004-05-18 Thread Luke Palmer
Damian Conway writes: > Austin Hastings wrote: > > >Hmm. For junctions I was thinking: > > > > ++ all([EMAIL PROTECTED]); > > > >Which is almost readable. > > But unfortunately not correct. Junctions are value, not lvalues. > > This situation is exactly what hyperoperators are for: > > ++Â

RE: idiom for filling a counting hash

2004-05-18 Thread Austin Hastings
> -Original Message- > From: Damian Conway [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 18 May, 2004 08:09 PM > To: [EMAIL PROTECTED] > Subject: Re: idiom for filling a counting hash > > > Austin Hastings wrote: > > > Hmm. For junctions I was thinking: &

Re: idiom for filling a counting hash

2004-05-18 Thread Damian Conway
Austin Hastings wrote: Hmm. For junctions I was thinking: ++ all([EMAIL PROTECTED]); Which is almost readable. But unfortunately not correct. Junctions are value, not lvalues. This situation is exactly what hyperoperators are for: ++Â [EMAIL PROTECTED]; Damian

RE: idiom for filling a counting hash

2004-05-18 Thread Austin Hastings
> -Original Message- > From: Luke Palmer > %a Â+Â= @a; > Is the operator you want. But, after all that, > > ++Â [EMAIL PROTECTED] > > Was probably the best way to do it all along. > Hmm. For junctions I was thinking: ++ all([EMAIL PROTECTED]); Which is almost readable.

Re: idiom for filling a counting hash

2004-05-18 Thread Aaron Sherman
On Tue, 2004-05-18 at 18:16, Juerd wrote: > St?phane Payrard skribis 2004-05-18 23:14 (+0200): > > I use over and over this idiom in perl5: > >$a{$_}++ for @a; > > This is nice and perlish but it gets easily pretty boring > > when dealing with many list/arrays and counting hashes. I never saw

Re: idiom for filling a counting hash

2004-05-18 Thread Luke Palmer
StÃphane Payrard writes: > I use over and over this idiom in perl5: > >$a{$_}++ for @a; > > This is nice and perlish but it gets easily pretty boring > when dealing with many list/arrays and counting hashes. > > I thought overloading the += operator > >%a += @a; Though that would like

Re: idiom for filling a counting hash

2004-05-18 Thread Juerd
John Williams skribis 2004-05-18 16:07 (-0600): > >$a{$_}++ for @a; > [EMAIL PROTECTED]; That's not a bad idea, even in Perl 5: 1;0 [EMAIL PROTECTED]:~$ perl -MBenchmark=cmpthese -e'my @foo = (1..16, 1..10); cmpthese -1, { a => sub { my %foo; $foo{$_}++ for @foo; }, i b => sub

Re: idiom for filling a counting hash

2004-05-18 Thread Juerd
St?phane Payrard skribis 2004-05-18 23:14 (+0200): > I use over and over this idiom in perl5: >$a{$_}++ for @a; > This is nice and perlish but it gets easily pretty boring > when dealing with many list/arrays and counting hashes. A3 says something about tr being able to return a histogram (a h

Re: idiom for filling a counting hash

2004-05-18 Thread Uri Guttman
> "JW" == John Williams <[EMAIL PROTECTED]> writes: JW> On Tue, 18 May 2004, Stéphane Payrard wrote: >> I use over and over this idiom in perl5: >> >> $a{$_}++ for @a; JW> [EMAIL PROTECTED]; i see dead languages (apl :) uri -- Uri Guttman -- [EMAIL PROTECTED] ---

Re: idiom for filling a counting hash

2004-05-18 Thread John Williams
On Tue, 18 May 2004, Stéphane Payrard wrote: > I use over and over this idiom in perl5: > >$a{$_}++ for @a; > In perl6, using a hash slice and a hyper(increment)operator: [EMAIL PROTECTED];