On 09/08/12 16:58, Nikita Popov wrote:
On Wed, Aug 8, 2012 at 10:55 PM, Andrew Faulds <a...@ajf.me> wrote:
Hmm. This is just a quick thought:

Considering the yield syntax will vary about needing () round it, why not
make it a "fake" function (language construct).

This way it's consistent: yield(), yield($v), yield($k => $v), $a = yield(),
etc.

(yield $x) is just messy as an expression. We don't have (isset $x), we have
isset($x).
There are two reasons why I would not choose that syntax:

1. This would make "yield" look like a functions, without actually
being a function. PHP has done this in the past quite often and I
think it was a mistake. It is the reason why people try to write
empty(someCall()). It looks like a function, so they expect it to
behave like one. Similarly you also can't do $f = 'empty'; $f($foo),
which again is confusing to people new to the language.
yield(), so far as the programmer is concerned, might as well be a function. It isn't, strictly speaking, but like other function calls, it suspends execution of the function until the called function completes.

So I don't think this is a problem.
2. Other languages that implement generators also use the "yield $foo"
syntax (and also have the same parentheses requirements). So this
makes PHP consistent with them.
Doesn't mean we can't lead the way and have a nicer syntax :)
Nikita


--
Andrew Faulds
http://ajf.me/


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

Reply via email to