> Am 10.03.2019 um 22:44 schrieb Larry Garfield <la...@garfieldtech.com>:
> 
> Hello, peoples.  I know it's been discussed once or twice before on the list, 
> many years ago, but not recently.  I therefore feel OK putting forth the 
> following draft proposal for Comprehensions, aka "compact generators", in PHP:
> 
> https://wiki.php.net/rfc/comprehensions
> 
> Sara Golemon has written a preliminary patch that is partially complete (see 
> the RFC link for details, it's impressively simple), but unfortunately 
> doesn't have the bandwidth to complete it at this time.  I am therefore 
> looking for collaborators with more knowledge of internals than I (which is 
> almost everyone) to help finish it up.
> 
> The syntax proposed is also subject to revision if a terser but still 
> lexer-friendly alternative can be proposed.
> 
> At the moment I'm not calling this Proposed yet, as I don't feel comfortable 
> doing so until someone else is on board to finish coding it.  That said, if 
> someone wants to weigh in on the concept for now (hopefully supportively) 
> that's also fine.
> 
> Anyone excited enough to help finish the job?
> 
> (This is my first RFC collaboration, so if you're going to smack me for 
> goofing something please be gentle about it.)
> 
> -- 
>  Larry Garfield
>  la...@garfieldtech.com

Hey Larry,
First, I like it. (the idea/intention behind of providing a compact way for 
list comprehensions)

Though in general, I think this would be better off implemented with a more 
flexible short closure; it feels like a special case of these. I.e. that the 
comprehension syntax can be simply desugared to an immediately invoked short 
closure. At that point also, it can be a compiler only patch, if we have short 
closures with the appropriate binding behavior.
I guess it should be pretty easy to build that on top of my existing short 
closures patch.

Regarding the syntax, I'd not conflate for with foreach, the distinction is 
built into PHP and as such should remain.
We also might have trivial argument-less short closures written as "{ stmt }" 
simply, having the comprehension written as $gen = {foreach($list as $x) if($x 
% 2) yield $x * 2;}(); (note the trailing "()" function call - if we desire to, 
we might make the semicolon at the end of that single-statement closure 
optional.)

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

Reply via email to