Re: [PHP-DEV] Re: [PHP-WEBMASTER] New wiki account

2012-05-12 Thread Dmitri Ravazin
On Sat, May 12, 2012 at 12:22 AM, Alexander Moskaliov ir...@irker.net wrote:
 2012/5/12 Dmitri Ravazin rava...@gmail.com

 Yes... That's just what I had in the RFC.


 Not at all. In RFC you use first expression in for ... else statement as
 condition for else statement.

 if (some_very_expensive_and_ugly_looking_calculation($array)  0) {

 }


  I think it correct to use the second expression before the start of
 looping, as I described in previous mail.

That if is testing the inverse condition of $exp2 from for, so it
will yield exactly the same result.
If some_very_expensive_and_ugly_looking_calculation($array) is less
than 0, then it can't be greater of equal than 0 at the same time, so
for loop will not be entered.
It is assumed, of course, that the function does not modify the data.
If it did, then yeah, we'd need a temporary variable.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: [PHP-WEBMASTER] New wiki account

2012-05-11 Thread Alexander Moskaliov
I think the main idea of ​​this RFC: Run the code, if we had never entered
in loop.
In this case more sence to change for .. else condition to this:
If second expression  is equal FALSE before looping(but after run first
expression of course), we run else code.

By example:
for (exp1;exp2;exp3) {
exp4;
} else {
exp5;
}

must be equal
$notLooping = true;
for (exp1;exp2;exp3) {
exp4;
$notLooping = false;
}
if ($notLooping) {
exp5;
}

With regards, Alexander Moskaliov
ir...@irker.net


2012/5/10 Dmitri Ravazin rava...@gmail.com

 Hi,

 I registered account 'ravazin' on wiki.
 I'd like to write an RFC based on bugs:

 https://bugs.php.net/bug.php?id=26411
 https://bugs.php.net/bug.php?id=46240
 https://bugs.php.net/bug.php?id=61222

 I think it's time these requests got some sort of resolution :)



Re: [PHP-DEV] Re: [PHP-WEBMASTER] New wiki account

2012-05-11 Thread Nikita Popov
On Fri, May 11, 2012 at 8:33 AM, Alexander Moskaliov ir...@irker.net wrote:
 I think the main idea of this RFC: Run the code, if we had never entered
 in loop.
 In this case more sence to change for .. else condition to this:
 If second expression  is equal FALSE before looping(but after run first
 expression of course), we run else code.

 By example:
 for (exp1;exp2;exp3) {
    exp4;
 } else {
    exp5;
 }

Python already uses the for .. else syntax, but with different
semantics: In Python the else clause is only executed, if the loop
isn't left using break. See this article for more info:
http://psung.blogspot.de/2007/12/for-else-in-python.html

Thus I'm not sure that it really makes sense for us to introduce this
syntax with a completely different meaning.

Nikita

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: [PHP-WEBMASTER] New wiki account

2012-05-11 Thread Dmitri Ravazin
On Fri, May 11, 2012 at 2:33 AM, Alexander Moskaliov ir...@irker.net wrote:

 I think the main idea of this RFC: Run the code, if we had never entered
 in loop.
 In this case more sence to change for .. else condition to this:
 If second expression  is equal FALSE before looping(but after run first
 expression of course), we run else code.

 By example:
 for (exp1;exp2;exp3) {
     exp4;
 } else {
     exp5;
 }

 must be equal
 $notLooping = true;
 for (exp1;exp2;exp3) {
     exp4;
     $notLooping = false;
 }
 if ($notLooping) {
     exp5;
 }


Yes... That's just what I had in the RFC.
Except I used the name $loop_entered, and then checked for it being
false, and you used variable $notLooping, and checked for it being
true.
That is the same thing.

Hey, I noticed you CC'ed internals, does that mean everyone on the
list is getting this?
Sorry, not entirely familiar with how these mailing lists work.


On Fri, May 11, 2012 at 6:21 AM, Nikita Popov nikita@googlemail.com wrote:
 Python already uses the for .. else syntax, but with different
 semantics: In Python the else clause is only executed, if the loop
 isn't left using break. See this article for more info:
 http://psung.blogspot.de/2007/12/for-else-in-python.html

 Thus I'm not sure that it really makes sense for us to introduce this
 syntax with a completely different meaning.

 Nikita

Python isn't always right in how it does things.
I find python for...else logic to have fewer real-life use-cases than
what is being proposed here.
I'm speaking from my experience, of course, and not saying it's true
for every project out there... But if the comments to those bugs are
any indication, it is true for most people.
You will notice that all 3 proposals (spanning almost 10 years)
advocate the non-python logic.

And even if you look at the example from your article, it does *not*
demonstrate usefulness of for...else in python.
I can write the same code without for...else and without any flag
variables by just returning from the function, instead of breaking:

def contains_even_number(l):
  Prints whether or not the list l contains an even number.
  for elt in l:
if elt % 2 == 0:
  print list contains an even number
  return
  print list does not contain an even number

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: [PHP-WEBMASTER] New wiki account

2012-05-11 Thread Kris Craig


 Hey, I noticed you CC'ed internals, does that mean everyone on the
 list is getting this?
 Sorry, not entirely familiar with how these mailing lists work.




Yep.  And at least for my part, I have no idea what RFC you guys are
talking about lol.  ;P

--Kris


Re: [PHP-DEV] Re: [PHP-WEBMASTER] New wiki account

2012-05-11 Thread Alexander Moskaliov
2012/5/12 Dmitri Ravazin rava...@gmail.com

 Yes... That's just what I had in the RFC.


Not at all. In RFC you use first expression in for ... else statement as
condition for else statement.

if (some_very_expensive_and_ugly_looking_calculation($array)  0) {

}


 I think it correct to use the second expression before the start of
looping, as I described in previous mail.


2012/5/12 Kris Craig kris.cr...@gmail.com

 Yep.  And at least for my part, I have no idea what RFC you guys are
 talking about lol.  ;P

Sorry, RFC link was in old thread: https://wiki.php.net/rfc/loop_else

With regards, Alexander Moskaliov
ir...@irker.net