On 24/07/12 19:06, Yahav Gindi Bar wrote:
You could introduce new keyword for generator... even call it "generator" but why (its
kind of "design" issue...)? if the syntax that one should use in order to implement the
generator is just like a function, but using yield keyword in order to return the items to store?
As long as I know, most programming languages that uses generators wrap it up
in a function, so why shall we introduce new keyword that can confuse
programmers?
I think using function and returning the value using yield is great... although
I'm open to any new nicely-written generator syntax.
On 24 ביול 2012, at 20:56, Alex Aulbach wrote:
2012/7/24 Andrew Faulds <a...@ajf.me>:
Much easier to make an iterator with a function than as a class.
2012/7/24 Yahav Gindi Bar <g.b.ya...@gmail.com>:
I agree, implementing a class only for iterator may be pain sometimes, and
functions is much better - especially when 5.3 got the anonymous functions, so
we can even use the generators for iterator functions in class methods which
can be great.
Ok, why not call it "iterator" or "generator" or "huffpuff" instead of
"function"? It's just the naming, which disturbs me, because a
function is something which is, when called once finished once. I
don't like mathematics, but that is one of the definition of a
function:
http://en.wikipedia.org/wiki/Function_%28mathematics%29
"each input is related to exactly one output"
Couldn't be so complicated to introduce a new name for that, or?
--
Alex Aulbach
And anyway it just depends on your perspective. It's still a function
IMO, it doesn't return, it yields. To me it's kinda like having a
function in another thread that passes several messages back over its
lifetime, and then finally returns.
--
Andrew Faulds
http://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php