Re: for ... else

2007-03-05 Thread Jonathan Lang
Larry Wall wrote: On Mon, Mar 05, 2007 at 04:13:16PM +1030, Tom Lanyon wrote: : Sounds like the following will work, but it doesn't seem 'nice'. : : for @invoice : { : .process; : 1; : } or fail 'No invoices to process'; Still think if there's no invoices it logically should be tested first. I

Re: for ... else

2007-03-04 Thread Tom Lanyon
Larry Wall wrote: Still think if there's no invoices it logically should be tested first. If you don't want to repeat mentioning the array, how 'bout: @invoice or fail 'No invoices to process' ==> for @() { .process } or equivalently @invoice or fail 'No invoices to pro

Re: for ... else

2007-03-04 Thread Larry Wall
On Mon, Mar 05, 2007 at 04:13:16PM +1030, Tom Lanyon wrote: : Sounds like the following will work, but it doesn't seem 'nice'. : : for @invoice : { : .process; : 1; : } or fail 'No invoices to process'; Still think if there's no invoices it logically should be tested first. If you don't want to

Re: for ... else

2007-03-04 Thread Tom Lanyon
Larry Wall wrote: On Mon, Mar 05, 2007 at 03:56:16PM +1030, Tom Lanyon wrote: : Larry Wall wrote: : >On Sun, Mar 04, 2007 at 06:37:34PM -0800, Jonathan Lang wrote: : >: Rick Delaney wrote: : >: >Smylers wrote: : >: >> for @invoice : >: >> { : >: >> .process; : >: >> } or fail 'No invoic

Re: for ... else

2007-03-04 Thread Larry Wall
On Mon, Mar 05, 2007 at 03:56:16PM +1030, Tom Lanyon wrote: : Larry Wall wrote: : >On Sun, Mar 04, 2007 at 06:37:34PM -0800, Jonathan Lang wrote: : >: Rick Delaney wrote: : >: >Smylers wrote: : >: >> for @invoice : >: >> { : >: >> .process; : >: >> } or fail 'No invoices to process'; : >:

Re: for ... else

2007-03-04 Thread Tom Lanyon
Larry Wall wrote: On Sun, Mar 04, 2007 at 06:37:34PM -0800, Jonathan Lang wrote: : Rick Delaney wrote: : >Smylers wrote: : >> for @invoice : >> { : >> .process; : >> } or fail 'No invoices to process'; : > : >If that actually works then I'm happy. : : It's dependent on .process not ret

Re: for ... else

2007-03-04 Thread Larry Wall
On Sun, Mar 04, 2007 at 06:37:34PM -0800, Jonathan Lang wrote: : Rick Delaney wrote: : >Smylers wrote: : >> for @invoice : >> { : >> .process; : >> } or fail 'No invoices to process'; : > : >If that actually works then I'm happy. : : It's dependent on .process not returning a false on th

Re: for ... else

2007-03-04 Thread Jonathan Lang
Rick Delaney wrote: Smylers wrote: > for @invoice > { > .process; > } or fail 'No invoices to process'; If that actually works then I'm happy. It's dependent on .process not returning a false on the final iteration. -- Jonathan "Dataweaver" Lang

Re: for ... else

2007-03-04 Thread Rick Delaney
On Mar 04 2007, Smylers wrote: > for @invoice > { > .process; > } or fail 'No invoices to process'; If that actually works then I'm happy. -- Rick Delaney [EMAIL PROTECTED]

Re: for ... else

2007-03-04 Thread Smylers
Steve Lukas writes: > On the other hand, there is no important reason for it because C< > > for @rray -> $el {} > if ! @rray {} > > > > should work. It's short and easy to understand. But it involves repeating C<@rray> -- which for more complex expressions (results from function calls, delving

Re: for ... else

2007-03-04 Thread Thomas Wittek
Steve Lukas schrieb: > More exceptional rules in a language are bad in itself. > Those exceptions force people to more to learn more stuff I guess that most people would understand the for/empty(/start/end) code without having ever written any line of Perl. They won't understand first/Any/gather d

Re: for ... else

2007-03-04 Thread Smylers
Andy Armstrong writes: > On 3 Mar 2007, at 00:39, Thomas Wittek wrote: > > > I'd like the For::Else behaviour more. Especially as I remember > > numerous times writing an if clause to check if a list is empty > > before processing it. > > That's crazy.

Re: for ... else

2007-03-04 Thread Jonathan Lang
Daniel Brockman wrote: What about this? given @foo { for $_ -> $x { ... } when .empty { ... } } You can reverse the order if you want: given @foo { when .empty { ... } for $_ -> $x { ... } } Actually, you'd be better off using the second order; the "when" stat

Re: for ... else

2007-03-04 Thread Daniel Brockman
What about this? given @foo { for $_ -> $x { ... } when .empty { ... } } You can reverse the order if you want: given @foo { when .empty { ... } for $_ -> $x { ... } } I don't like C<$_>, but I can't think of a way to get rid of it. -- Daniel Brockman <[EMAIL P

Re: for ... else

2007-03-04 Thread Steve Lukas
I vote against this proposal. More exceptional rules in a language are bad in itself. Those exceptions force people to more to learn more stuff and lead to confusion for those who don't know every detail of this language. So, there should be an important reason for that or it's a silly idea. I

Re: for ... else

2007-03-04 Thread Andy Armstrong
On 3 Mar 2007, at 00:39, Thomas Wittek wrote: I'd like the For::Else behaviour more. Especially as I remember numerous times writing an if clause to check if a list is empty before processing it. That's crazy. If the list is empty foreach still does the right thing - there'

Re: for ... else

2007-03-04 Thread Thomas Wittek
Darren Duncan schrieb: > At 11:17 PM +0100 3/3/07, Thomas Wittek wrote: >> Larry Wall: >>> : if ($item = 'foobar') { >> >> == of course ;) >>> If you actually wrote that, then you'll always find that the first >> > item has the value 'foobar'. :) > > Care to try a third time? > > I don't

Re: for ... else

2007-03-04 Thread Jonathan Lang
Jonathan Lang wrote: Seconded. I would favor allowing an "else" block to be attached following any loop block, with the semantics being that the else block only gets triggered if the loop block doesn't run at least once. I'd do this instead of a block trait (such as FIRST or LAST) because of th

Re: for ... else

2007-03-04 Thread Jonathan Lang
herbert breunung wrote: > Von: Thomas Wittek <[EMAIL PROTECTED]> > That's, well, elegant! Yes. > Because and but it's tricky. > Nothing where I'd say "wow, thats an easy solution to my problem!". > It's a bit complicated, because you have to understand and combine > several concepts. That's elega

Re: for ... else

2007-03-04 Thread herbert breunung
> Von: Thomas Wittek <[EMAIL PROTECTED]> > That's, well, elegant! Yes. > Because and but it's tricky. > Nothing where I'd say "wow, thats an easy solution to my problem!". > It's a bit complicated, because you have to understand and combine > several concepts. That's elegant. But not easy, I think

Re: for ... else

2007-03-03 Thread Juerd Waalboer
Thomas Wittek skribis 2007-03-03 23:17 (+0100): > Larry Wall: > > : if ($item = 'foobar') { > == of course ;) Or how about eq? :) -- korajn salutojn, juerd waalboer: perl hacker <[EMAIL PROTECTED]> convolution: ict solutions and consultancy <[EMAIL PROTECTED]

Re: for ... else

2007-03-03 Thread Darren Duncan
At 11:17 PM +0100 3/3/07, Thomas Wittek wrote: Larry Wall: : if ($item = 'foobar') { == of course ;) If you actually wrote that, then you'll always find that the first > item has the value 'foobar'. :) Care to try a third time? I don't think the numeric-casting == will do what yo

Re: for ... else

2007-03-03 Thread Thomas Wittek
Larry Wall: > : if ($item = 'foobar') { == of course ;) > If you actually wrote that, then you'll always find that the first > item has the value 'foobar'. :) > Well, leaving out the extraneous stuff, here's both kinds of "else" in one: > > $result = first 42, (@items || say "No items.

Re: for ... else

2007-03-03 Thread Larry Wall
On Sat, Mar 03, 2007 at 01:39:35AM +0100, Thomas Wittek wrote: : Luke Palmer schrieb: : > That is not what it means in Python. : : You trapped me. :) Actually I don't know any python but I've once read a : for/else construct in python. But obviously it doesn't dwIm. :

Re: for ... else

2007-03-02 Thread Thomas Wittek
Luke Palmer schrieb: > That is not what it means in Python. You trapped me. :) Actually I don't know any python but I've once read a for/else construct in python. But obviously it doesn't dwIm. >From the Python Reference Manual: When the items are exhausted (which is

Re: for ... else

2007-03-02 Thread Rick Delaney
On Mar 02 2007, Luke Palmer wrote: > Or I wonder if there's really a problem here that we're > addressing, or whether we're just adding syntax because we can. This syntax awkwardness comes up a lot in various kinds of reports. for @records { .print; } if @records { say

Re: for ... else

2007-03-02 Thread Luke Palmer
On 3/2/07, Thomas Wittek <[EMAIL PROTECTED]> wrote: Today I stumbled upon the Perl5 module For::Else. It adds an else block to a foreach loop: foreach my $item (@items) { #process each item } else { #handle the empty list case } I find it a very nice addition as I've w

Re: for ... else

2007-03-02 Thread Paul Seamons
> foreach my $item (@items) { > #process each item > } else { > #handle the empty list case > } > > What do you think? I'm not sure if I like it, but there have been several times that I would've used it recently. I think it would certainly have utility. Paul

for ... else

2007-03-02 Thread Thomas Wittek
Today I stumbled upon the Perl5 module For::Else. It adds an else block to a foreach loop: foreach my $item (@items) { #process each item } else { #handle the empty list case } I find it a very nice addition as I've written code like this: if (@stuff) { for my $thing (@