Re: [RFC] Loop... or...

From: Date: Sun, 21 Sep 2014 00:21:58 +0000
Subject: Re: [RFC] Loop... or...
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-77398@lists.php.net to get a copy of this message
On Sat, Sep 20, 2014 at 3:03 PM, Leigh <leight@gmail.com> wrote: > On 20 September 2014 20:47, Sara Golemon <php@golemon.com> wrote: >> I like the general idea, but rather than explicitly focusing on the 'or' keyword, >> how about just giving all loop constructs (do/while/for/foreach) a return value? I'd suggest >> an integer return value indicating the number of times the loop executed. >> > > mind === blown > > This would open up a huge amount of other functionality I'd never > dreamed of (some of which is quite scary!) > > for($i = for(...) {}; $i < ...) {} > Yikes, I truly hope nobody ever writes that code. Ever. > I'm really not sure I understand the full implication of this though. > This would mean changing loop constructs from statements to > expressions. I wonder how difficult that will actually be, and what > other problems it would cause (I obviously haven't played with this > idea yet). > I admit, I haven't thought it through entirely either. Nor even if it's definitely possible. > It would also mean having to make { default block } into an > expression... with a return value (to be allowed on either side of the > boolean or) > Excellent point, a block only works with T_OR if it has a value. I'm pretty sure that at this point, it doesn't. That does put a monkey wrench into it. Perhaps a lambda could accommodate that? Starts to get ugly though... > Lots to think about here, if it's at all viable this will need it's > own separate RFC, it's a much more invasive change, but definitely a > great idea. > Yeah, I might be trying too hard. Worth exploring a tiny bit though... -Sara

« previous php.internals (#77398) next »