Re: list comprehensions

2002-11-07 Thread Damian Conway
Piers Cawley pointed out: %a_students = grep {.key ~~ :i/^a/}, %grades.kv; I think you could probably get away without the .kv there since, in a list context you're going to get a list of pairs anyway. In fact, the code is invalid as it stands. The following variations work as desired: %a_s

Re: list comprehensions

2002-11-06 Thread Piers Cawley
"Adam D. Lopresto" <[EMAIL PROTECTED]> writes: >> I don't see why I'd want to do it with arrays, but... >> >> %a_students = %grades{grep /^a/i, keys %grades}; > > Looks like that's just the same as > > %a_students = grep {.key ~~ :i/^a/}, %grades.kv; I think you could probably get away without

Re: list comprehensions

2002-11-06 Thread Jonathan Scott Duff
On Wed, Nov 06, 2002 at 11:36:50AM -0800, Larry Wall wrote: > You know, guys, I already discussed this one in A4 or thereabouts. > It's the use of an explicit boolean operator as a subscript that > triggers selection. I thought so, but I couldn't find it. thanks, -Scott -- Jonathan Scott Duff [

Re: list comprehensions

2002-11-06 Thread Adam D. Lopresto
> I don't see why I'd want to do it with arrays, but... > > %a_students = %grades{grep /^a/i, keys %grades}; Looks like that's just the same as %a_students = grep {.key ~~ :i/^a/}, %grades.kv; (after adjusting for perl6 syntax for a few things) -- Adam Lopresto ([EMAIL PROTECTED]) http://cec.

Re: list comprehensions

2002-11-06 Thread Larry Wall
You know, guys, I already discussed this one in A4 or thereabouts. It's the use of an explicit boolean operator as a subscript that triggers selection. Larry

Re: list comprehensions

2002-11-06 Thread Me
> Will there be some shorter-hand way to say these? > [list comprehensions] (bb clarified that this is about hash slicing.) >From A2: RFC 201: Hash Slicing ...Concise list comprehensions will require some other syntax within the subscript... And There are many ways

Re: list comprehensions

2002-11-06 Thread Austin Hastings
--- Buddha Buck <[EMAIL PROTECTED]> wrote: > I think that if there were a slice-based form of grep, it would most > likely look like you are indexing by a subroutine (or method) > reference > that takes no arguments other than an element of the array. > Something like: > >@a = @grades[{$^x

Re: list comprehensions

2002-11-06 Thread Buddha Buck
Piers Cawley wrote: Jonathan Scott Duff <[EMAIL PROTECTED]> writes: Will there be some shorter-hand way to say these? @a = @grades[grep $_ >= 90, @grades]; @b = @grades[grep 80 <= $_ < 90, @grades]; @c = @grades[grep 70 <= $_ < 80, @grades]; Granted, it's fairly compact as it is but I'm wo

Re: list comprehensions

2002-11-06 Thread Buddha Buck
Jonathan Scott Duff wrote: On Wed, Nov 06, 2002 at 12:54:12PM -0500, Mark J. Reed wrote: On 2002-11-06 at 11:43:20, Jonathan Scott Duff wrote: Will there be some shorter-hand way to say these? @a = @grades[grep $_ >= 90, @grades]; @b = @grades[grep 80 <= $_ < 90, @grades]; @c = @grades[gre

Re: list comprehensions

2002-11-06 Thread Simon Cozens
[EMAIL PROTECTED] (Piers Cawley) writes: > I confess I never quite understood why the python folks were so proud > of list comprehensions, AFAICT they're just 'grep' and 'map' given > fancy descriptions. Well, sort of. They're more like this: @arr

Re: list comprehensions

2002-11-06 Thread Piers Cawley
@a = @grades[$^_ >= 90]; > @b = @grades[80 <= $^_ < 90]; > @c = @grades[70 <= $^_ < 80]; > > BTW, is there some other name for these things? I only know to call > them "list comprehensions" from python. I've used the conce

Re: list comprehensions

2002-11-06 Thread Jonathan Scott Duff
On Wed, Nov 06, 2002 at 12:54:12PM -0500, Mark J. Reed wrote: > > On 2002-11-06 at 11:43:20, Jonathan Scott Duff wrote: > > > > Will there be some shorter-hand way to say these? > > > > @a = @grades[grep $_ >= 90, @grades]; > > @b = @grades[grep 80 <= $_ < 90, @grades]; > > @c = @gra

Re: list comprehensions

2002-11-06 Thread Mark J. Reed
On 2002-11-06 at 11:43:20, Jonathan Scott Duff wrote: > > Will there be some shorter-hand way to say these? > > @a = @grades[grep $_ >= 90, @grades]; > @b = @grades[grep 80 <= $_ < 90, @grades]; > @c = @grades[grep 70 <= $_ < 80, @grades]; I think what you mean here is just

list comprehensions

2002-11-06 Thread Jonathan Scott Duff
#x27;s some way to not have to mention @grades twice per statement. Something like: @a = @grades[$^_ >= 90]; @b = @grades[80 <= $^_ < 90]; @c = @grades[70 <= $^_ < 80]; BTW, is there some other name for these things? I only know to call them "list comprehens