Re: Please make "last" work in "grep"

2001-05-10 Thread Mark-Jason Dominus
On (03 May 2001 10:23:15 +0300) you wrote: > Michael Schwern: > > > > Would be neat if: my($first) = grep {...} @list; knew to stop itself, yes. > > > > It also reminds me of mjd's mention of: my($first) = sort {...} @list; > > being O(n) if Perl were really Lazy. > > But it would need a

Re: Please make "last" work in "grep"

2001-05-03 Thread David L. Nicol
> > It also reminds me of mjd's mention of: my($first) = sort {...} @list; > > being O(n) if Perl were really Lazy. > > But it would need a completely different algorithm. Which is not too > bad. And even > > my ($first, $second, $third) = sort {...} @list; > > is kind-of plausible. So

Re: Please make "last" work in "grep"

2001-05-03 Thread James Mastros
From: "Alexander Farber (EED)" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, May 02, 2001 5:13 AM Subject: Please make "last" work in "grep" > Here I am looking for a button with a special name - "Delete ..." - > and the

Re: Please make "last" work in "grep"

2001-05-03 Thread Ariel Scolnicov
Michael G Schwern <[EMAIL PROTECTED]> writes: > On Wed, May 02, 2001 at 08:05:29AM -0700, Larry Wall wrote: > > Michael G Schwern writes: > > : (grep {...} @stuff)[0] will work, but its inelegant. > > > > It's inelegant only because the slice doesn't know how to tell the > > iterator it only nee

Re: Please make "last" work in "grep"

2001-05-02 Thread Larry Wall
[EMAIL PROTECTED] writes: :> >Hopefully the "something similar", I hope in Perl 6 we will able to :> >bury the "0 but true" workaround to the backyard on a moonless night :-) :> :> Especially since you don't need it. "0E0" and "0.", to name just two, :> work just as well. ;-

Re: Please make "last" work in "grep"

2001-05-02 Thread David L. Nicol
Graham Barr wrote: > How this cooperates with lazy is a different matter entirely. > > Graham. http://dev.perl.org/rfc/123.html#Assigning_from_lazy_lists suggests that assigning to a sized busy array from a lazy array will fill it and stop. -- David Nicol 816.235.1187 [

Re: Please make "last" work in "grep"

2001-05-02 Thread Dan Sugalski
At 06:06 AM 5/3/2001 +1000, Damian Conway wrote: >> >Hopefully the "something similar", I hope in Perl 6 we will able to >> >bury the "0 but true" workaround to the backyard on a moonless > night :-) >> >> Especially since you don't need it. "0E0" and "0.", to name just two, >

Re: Please make "last" work in "grep"

2001-05-02 Thread Damian Conway
> >Hopefully the "something similar", I hope in Perl 6 we will able to > >bury the "0 but true" workaround to the backyard on a moonless night :-) > > Especially since you don't need it. "0E0" and "0.", to name just two, > work just as well. ;-) http://yetanother.org/damian/Perl

Re: Please make "last" work in "grep"

2001-05-02 Thread Damian Conway
> > Because you might have a wantarray situation that expects no values? > > > > () = whateveryouwant(); > > I am sure that situation is handled by the 'want' RFC. Yep. The most recent version is at: http://www.yetanother.org/damian/Perl5+i/want.html > I have not re

Re: Please make "last" work in "grep"

2001-05-02 Thread Bart Lateur
On Wed, 2 May 2001 11:41:32 -0500, Jarkko Hietaniemi wrote: >but I suspect in this case want('LIST') would >> return that magical "0 but true" or something similar. > >Hopefully the "something similar", I hope in Perl 6 we will able to >bury the "0 but true" workaround to the backyard on a moonle

Re: Please make "last" work in "grep"

2001-05-02 Thread Dan Sugalski
At 09:58 AM 5/2/2001 -0700, Larry Wall wrote: >Dan Sugalski writes: >: I'd really like to get into the details of what is and isn't valid for the >: optimizer to do, though I expect it's still a little early in the >: Apocalypse season for that. > >Doubtless we'll do as other compilers do, and hav

Re: Please make "last" work in "grep"

2001-05-02 Thread Larry Wall
Dan Sugalski writes: : I'd really like to get into the details of what is and isn't valid for the : optimizer to do, though I expect it's still a little early in the : Apocalypse season for that. Doubtless we'll do as other compilers do, and have a little knob you just keep turning up until som

Re: Please make "last" work in "grep"

2001-05-02 Thread Larry Wall
Bart Lateur writes: : Because you might have a wantarray situation that expects no values? : : () =3D whateveryouwant(); : : You can always expect one more than is on the LHS. : : How is this currently handled with split()? It fakes up a third argument that is one more than the length of

Re: Please make "last" work in "grep"

2001-05-02 Thread John Porter
Michael G Schwern wrote: > If we could determine if the block has no side effects... oh wait, > everything in Perl has a side effect. ;) :pure (again!) -- John Porter

Re: Please make "last" work in "grep"

2001-05-02 Thread Dan Sugalski
At 09:29 AM 5/2/2001 -0700, Larry Wall wrote: >H.Merijn Brand writes: >: wanting the side effects of grep/map finishing over all elements (which >could >: of course be from a tied array or database connection) > >If we do that kind of optimization, then we would certainly provide >some kind of ea

Re: Please make "last" work in "grep"

2001-05-02 Thread Jarkko Hietaniemi
On Wed, May 02, 2001 at 05:36:11PM +0100, Graham Barr wrote: > On Wed, May 02, 2001 at 06:29:51PM +0200, Bart Lateur wrote: > > On Wed, 2 May 2001 17:05:31 +0100, Graham Barr wrote: > > > > >wantarray-ness is already passed along the call stack today. Thats > > >the whole point of it. So what is

Re: Please make "last" work in "grep"

2001-05-02 Thread Graham Barr
On Wed, May 02, 2001 at 06:29:51PM +0200, Bart Lateur wrote: > On Wed, 2 May 2001 17:05:31 +0100, Graham Barr wrote: > > >wantarray-ness is already passed along the call stack today. Thats > >the whole point of it. So what is the difference in passing a number > >instead of a boolean ? > > Becau

Re: Please make "last" work in "grep"

2001-05-02 Thread Larry Wall
H.Merijn Brand writes: : On Wed, 2 May 2001 08:05:29 -0700 (PDT), Larry Wall <[EMAIL PROTECTED]> wrote: : > Michael G Schwern writes: : > : (grep {...} @stuff)[0] will work, but its inelegant. : > : > It's inelegant only because the slice doesn't know how to tell the : > iterator it only needs on

Re: Please make "last" work in "grep"

2001-05-02 Thread Bart Lateur
On Wed, 2 May 2001 17:05:31 +0100, Graham Barr wrote: >wantarray-ness is already passed along the call stack today. Thats >the whole point of it. So what is the difference in passing a number >instead of a boolean ? Because you might have a wantarray situation that expects no values? ()

Re: Please make "last" work in "grep"

2001-05-02 Thread Michael G Schwern
On Wed, May 02, 2001 at 06:05:54PM +0200, H. Merijn Brand wrote: > IIRC, that optimization is not even considered for reasons of many people > wanting the side effects of grep/map finishing over all elements (which could > of course be from a tied array or database connection) If we could determi

Re: Please make "last" work in "grep"

2001-05-02 Thread H . Merijn Brand
On Wed, 2 May 2001 08:05:29 -0700 (PDT), Larry Wall <[EMAIL PROTECTED]> wrote: > Michael G Schwern writes: > : (grep {...} @stuff)[0] will work, but its inelegant. > > It's inelegant only because the slice doesn't know how to tell the > iterator it only needs one value. If it did know, you'd cal

Re: Please make "last" work in "grep"

2001-05-02 Thread Graham Barr
On Wed, May 02, 2001 at 12:01:24PM -0400, Uri Guttman wrote: > > "GB" == Graham Barr <[EMAIL PROTECTED]> writes: > > GB> On Wed, May 02, 2001 at 04:30:07PM +0100, Michael G Schwern wrote: > >> On Wed, May 02, 2001 at 08:05:29AM -0700, Larry Wall wrote: > >> > Michael G Schwern writes: >

Re: Please make "last" work in "grep"

2001-05-02 Thread Uri Guttman
> "GB" == Graham Barr <[EMAIL PROTECTED]> writes: GB> On Wed, May 02, 2001 at 04:30:07PM +0100, Michael G Schwern wrote: >> On Wed, May 02, 2001 at 08:05:29AM -0700, Larry Wall wrote: >> > Michael G Schwern writes: >> > : (grep {...} @stuff)[0] will work, but its inelegant. >> >

Re: Please make "last" work in "grep"

2001-05-02 Thread Graham Barr
On Wed, May 02, 2001 at 04:30:07PM +0100, Michael G Schwern wrote: > On Wed, May 02, 2001 at 08:05:29AM -0700, Larry Wall wrote: > > Michael G Schwern writes: > > : (grep {...} @stuff)[0] will work, but its inelegant. > > > > It's inelegant only because the slice doesn't know how to tell the > >

Re: Please make "last" work in "grep"

2001-05-02 Thread Michael G Schwern
On Wed, May 02, 2001 at 08:05:29AM -0700, Larry Wall wrote: > Michael G Schwern writes: > : (grep {...} @stuff)[0] will work, but its inelegant. > > It's inelegant only because the slice doesn't know how to tell the > iterator it only needs one value. If it did know, you'd call it > elegant. :-

Re: Please make "last" work in "grep"

2001-05-02 Thread Larry Wall
Michael G Schwern writes: : (grep {...} @stuff)[0] will work, but its inelegant. It's inelegant only because the slice doesn't know how to tell the iterator it only needs one value. If it did know, you'd call it elegant. :-) Larry

Re: Please make "last" work in "grep"

2001-05-02 Thread John Porter
Michael G Schwern wrote: > And I'm quite sure there's an RFC for doing something like this alread > up for Perl 6. At least RFC 199, and several related threads such as "$a in @b". -- John Porter It's so mysterious, the land of tears.

Re: Please make "last" work in "grep"

2001-05-02 Thread Graham Barr
On Wed, May 02, 2001 at 11:10:22AM +0100, Michael G Schwern wrote: > On Wed, May 02, 2001 at 11:13:13AM +0200, Alexander Farber (EED) wrote: > > I would like to propose adding the "last" statement > > to the "grep", which currently doesn't work: > > For the record, I have no problem with this. :)

Re: Please make "last" work in "grep"

2001-05-02 Thread Michael G Schwern
On Wed, May 02, 2001 at 11:13:13AM +0200, Alexander Farber (EED) wrote: > I would like to propose adding the "last" statement > to the "grep", which currently doesn't work: For the record, I have no problem with this. :) > maas34: perl -e 'grep { print and $_ == 3 and last } (1,2,3,4,5)' >

Please make "last" work in "grep"

2001-05-02 Thread Alexander Farber (EED)
Hi, I would like to propose adding the "last" statement to the "grep", which currently doesn't work: maas34: perl -e 'grep { print and $_ == 3 and last } (1,2,3,4,5)' 123 Can't "last" outside a loop block at -e line 1. This way it would be possible to use such constructs: print_header