Re: [PHP-DEV] Re: Generators in PHP

2012-08-19 Thread Nikita Popov
On Sun, Aug 19, 2012 at 6:28 AM, Stas Malyshev smalys...@sugarcrm.com wrote: Hi! For PHP we would need to have some similar behavior. PHP's current exception model is incompatible with GeneratorExitException (because PHP does not have BaseExceptions). So what I'd probably do instead is

Re: [PHP-DEV] Re: Generators in PHP

2012-08-19 Thread Derick Rethans
On Sun, 19 Aug 2012, Nikita Popov wrote: On Sun, Aug 19, 2012 at 6:28 AM, Stas Malyshev smalys...@sugarcrm.com wrote: For PHP we would need to have some similar behavior. PHP's current exception model is incompatible with GeneratorExitException (because PHP does not have

Re: [PHP-DEV] Re: Generators in PHP

2012-08-19 Thread Andrew Faulds
On 19/08/12 17:03, Derick Rethans wrote: On Sun, 19 Aug 2012, Nikita Popov wrote: On Sun, Aug 19, 2012 at 6:28 AM, Stas Malyshev smalys...@sugarcrm.com wrote: For PHP we would need to have some similar behavior. PHP's current exception model is incompatible with GeneratorExitException

Re: [PHP-DEV] Re: Generators in PHP

2012-08-19 Thread Nikita Popov
On Sun, Aug 19, 2012 at 6:03 PM, Derick Rethans der...@php.net wrote: On Sun, 19 Aug 2012, Nikita Popov wrote: On Sun, Aug 19, 2012 at 6:28 AM, Stas Malyshev smalys...@sugarcrm.com wrote: For PHP we would need to have some similar behavior. PHP's current exception model is incompatible

Re: [PHP-DEV] Re: Generators in PHP

2012-08-18 Thread Nikita Popov
On Thu, Aug 9, 2012 at 4:49 AM, Sherif Ramadan theanomaly...@gmail.com wrote: One question, though: It looks based on the voting like finally {} blocks are going in. So... what should happen in the following situation: function stuff() { try { foreach (range(1, 100) as $i) {

Re: [PHP-DEV] Re: Generators in PHP

2012-08-18 Thread Nikita Popov
On Thu, Aug 9, 2012 at 4:49 AM, Sherif Ramadan theanomaly...@gmail.com wrote: One question, though: It looks based on the voting like finally {} blocks are going in. So... what should happen in the following situation: function stuff() { try { foreach (range(1, 100) as $i) {

Re: [PHP-DEV] Re: Generators in PHP

2012-08-18 Thread Stas Malyshev
Hi! For PHP we would need to have some similar behavior. PHP's current exception model is incompatible with GeneratorExitException (because PHP does not have BaseExceptions). So what I'd probably do instead is monkeypatch a ZEND_RETURN opcode at the current execution position and Patching

RE: [PHP-DEV] Re: Generators in PHP

2012-08-09 Thread Ford, Mike
-Original Message- From: Andrew Faulds [mailto:a...@ajf.me] Sent: 25 July 2012 18:03 [...] Fact: Adding a new name for a special kind of function as a syntax construct is going to cost (possibly unnecessary) time and energy, because now you have functions, and weird things that

Re: [PHP-DEV] Re: Generators in PHP

2012-08-08 Thread Larry Garfield
On 07/27/2012 07:23 AM, Lester Caine wrote: Nikita Popov wrote: I'll ask again since no one has answered ... In a different way ... Is the only thing that changes the 'function' into a 'generator' replacing the call to process the data with 'yield'? ( That would be 'SUSPEND' in an SQL

Re: [PHP-DEV] Re: Generators in PHP

2012-08-08 Thread Sherif Ramadan
One question, though: It looks based on the voting like finally {} blocks are going in. So... what should happen in the following situation: function stuff() { try { foreach (range(1, 100) as $i) { yield $i; } } finally { print All done; } } Does All done

Re: Re: [PHP-DEV] Re: Generators in PHP

2012-08-08 Thread Morgan L. Owens
On 2012-08-09 14:25, Larry Garfield wrote: On 07/27/2012 07:23 AM, Lester Caine wrote: Nikita - I am looking for a well reasoned argument as to why generator has to be added at all! 'Just because it can be' is not a valid argument, but perhaps you could add to the RFC the performance

Re: [PHP-DEV] Re: Generators in PHP

2012-07-30 Thread Alex Aulbach
2012/7/28 Rasmus Lerdorf ras...@lerdorf.com: Very early versions of PHP v1 actually had distinct list, map and set implementations but I replaced those early on with a unified hybrid ordered map implementation and just called it the Array type. The thinking was that in almost all situations in

Re: [PHP-DEV] Re: Generators in PHP

2012-07-28 Thread Rasmus Lerdorf
On 07/26/2012 11:36 PM, Alex Aulbach wrote: 1) The bigger the language grows, the more we need to think about how to implement new features. I think it's a bad argument to say we made this and that not so ideal, so we can make this also. Don't be so idealistic. :) I think it's a duty to make

Re: [PHP-DEV] Re: Generators in PHP

2012-07-28 Thread Lester Caine
Rasmus Lerdorf wrote: I don't think this generator question is any different. We need to explain generators in the simplest way possible. The simplest way to explain generators is to not even worry about them being generators at all. Simply say that functions can now return arrays one element at

Re: [PHP-DEV] Re: Generators in PHP

2012-07-28 Thread Rasmus Lerdorf
On 07/27/2012 11:59 PM, Lester Caine wrote: Rasmus Lerdorf wrote: I don't think this generator question is any different. We need to explain generators in the simplest way possible. The simplest way to explain generators is to not even worry about them being generators at all. Simply say that

Re: [PHP-DEV] Re: Generators in PHP

2012-07-28 Thread Lester Caine
Rasmus Lerdorf wrote: I don't think this generator question is any different. We need to explain generators in the simplest way possible. The simplest way to explain generators is to not even worry about them being generators at all. Simply say that functions can now return arrays one element at

Re: [PHP-DEV] Re: Generators in PHP

2012-07-28 Thread Rasmus Lerdorf
On 07/28/2012 12:37 AM, Lester Caine wrote: Rasmus Lerdorf wrote: I don't think this generator question is any different. We need to explain generators in the simplest way possible. The simplest way to explain generators is to not even worry about them being generators at all. Simply say

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Alex Aulbach
2012/7/26 Rasmus Lerdorf ras...@lerdorf.com: A generator is enough like a function that we don't need a new keyword for it. We typically don't get too pedantic in PHP concepts and try to keep things simple. What we call an array isn't technically an array either. It's an ordered map, but it

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Lester Caine
Lester Caine wrote: Fact: yield makes functions some kind of different. Yes, they turn normal functions into continuation functions (functions which can be exited and reentered dynamically). But WHY would you not simply put the function that is handling the returned data in place of the

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Nikita Popov
On Fri, Jul 27, 2012 at 9:56 AM, Lester Caine les...@lsces.co.uk wrote: I'll ask again since no one has answered ... In a different way ... Is the only thing that changes the 'function' into a 'generator' replacing the call to process the data with 'yield'? ( That would be 'SUSPEND' in an

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Lester Caine
Nikita Popov wrote: I'll ask again since no one has answered ... In a different way ... Is the only thing that changes the 'function' into a 'generator' replacing the call to process the data with 'yield'? ( That would be 'SUSPEND' in an SQL procedure ) ... So how DOES an IDE work out the flow

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Sherif Ramadan
Nikita - I am looking for a well reasoned argument as to why generator has to be added at all! 'Just because it can be' is not a valid argument, but perhaps you could add to the RFC the performance implication or advantage of what is being proposed. That would at least be some comparison

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Andrew Faulds
On 27/07/12 13:23, Lester Caine wrote: Nikita Popov wrote: I'll ask again since no one has answered ... In a different way ... Is the only thing that changes the 'function' into a 'generator' replacing the call to process the data with 'yield'? ( That would be 'SUSPEND' in an SQL procedure

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Lester Caine
Sherif Ramadan wrote: https://wiki.php.net/rfc/generators#performance You can find a small micro benchmark at https://gist.github.com/2975796. It compares several ways of iterating ranges: What part of this discussion led you to believe such a ridiculous argument as to why generator were

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Sara Golemon
The micro benchmark is just that, and is not as far as I can see testing the sort of iterating process that would happen normally when going through a data set. It simply times the iterator, but does not compare like with like! I hear your concerns about performance, and you're good to

Re: [PHP-DEV] Re: Generators in PHP

2012-07-27 Thread Nikita Popov
On Wed, Jul 25, 2012 at 10:36 PM, Lester Caine les...@lsces.co.uk wrote: But WHY would you not simply put the function that is handling the returned data in place of the yield? Why do you want to keep exiting and re-entering the 'do loop' when the data can simply be forwarded direct to a

Re: [PHP-DEV] Re: Generators in PHP

2012-07-26 Thread Nikita Popov
On Wed, Jul 25, 2012 at 11:00 PM, Jared Williams jared.willia...@ntlworld.com wrote: Though here is seemingly another problem, though it could be within spl's MultipleIterator() Thanks, this is fixed now (see https://github.com/nikic/php-src/commit/268740d9848d435054ce73a8cfe36b2b732cd1f7). It

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Sherif Ramadan theanomaly...@gmail.com: PHP made implementation mistakes in the past that led to awkward behavior (like objects passed by value in PHP4), but that's never stopped things from moving forward and offering up useful features that users want. I think putting the technical

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Alex Aulbach wrote: PHP made implementation mistakes in the past that led to awkward behavior (like objects passed by value in PHP4), but that's never stopped things from moving forward and offering up useful features that users want. I think putting the technical details aside the engine can

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Sherif Ramadan
I like that kind of agile programming, too. But if someone like me says come on, lets make it a little bit more easy, because returning objects from functions is some kind of unconventional; many developers will make mistakes here... - why not? They will. I can tell by sure. What are

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Sherif Ramadan wrote: Just between PHP 5.2 and 5.4 we've gained traits, closures, namespaces, function array derefrencing, access to member upon instantiation, and lots of other lovely additions to the language. I don't see languages like Java or Python evolving this quickly -- by contrast.

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Ferenc Kovacs
( I'll start a new thread for my other rant ... ) nah, you won't, you will bring that up in every thread instead. -- Ferenc Kovács @Tyr43l - http://tyrael.hu

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Sherif Ramadan
Just between PHP 5.2 and 5.4 we've gained traits, closures, namespaces, function array derefrencing, access to member upon instantiation, and lots of other lovely additions to the language. I don't see languages like Java or Python evolving this quickly -- by contrast. But now we also need

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
Like they have already... :/ Sent from Samsung Mobile Ferenc Kovacs tyr...@gmail.com wrote: ( I'll start a new thread for my other rant ... ) nah, you won't, you will bring that up in every thread instead. -- Ferenc Kovács @Tyr43l - http://tyrael.hu

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Sherif Ramadan wrote: I don't see anything about these particular features that isn't already documented. Albeit there are parts of the documentation that could always use a bit of refinement every now and then. With that said, the manual isn't a place to tell people how a particular feature

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
Generators aren't for you, then, they are for people like me who, for example, used a C# generator for yielding tokens, or, for example, use generators to iterate element by element through multi-dimensional arrays. -- Sent from Samsung Mobile Andrew Faulds http://ajf.me/ Lester Caine

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Andrew Faulds wrote: Generators aren't for you, then, they are for people like me who, for example, used a C# generator for yielding tokens, or, for example, use generators to iterate element by element through multi-dimensional arrays. Such as the family tree created by iterating through a

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Sherif Ramadan theanomaly...@gmail.com: I don't understand what you find non-conventional about functions or methods that return objects. Again: I don't have any problems with the object returning. :) I see a problem that the mechanism isn't understood and used wrong. And I think,

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Andrew Faulds a...@ajf.me: Generators aren't for you, then, they are for people like me who, for example, used a C# generator for yielding tokens, or, for example, use generators to iterate element by element through multi-dimensional arrays. Then make it in the PHP way not in the

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Sherif Ramadan
Again: I don't have any problems with the object returning. :) I see a problem that the mechanism isn't understood and used wrong. Isn't understood by who? Used wrong by who? Are we talking about people using a feature, that doesn't exist yet in PHP, the wrong way and arguing that there

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
We, of course, should try to avoid user confusion if it will be a big issue. But I don't see any here. Also, 20 years experience does not necessarily a good programmer make, nor an expert in other programmers. -- Sent from Samsung Mobile Andrew Faulds http://ajf.me/ Sherif Ramadan

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Ferenc Kovacs
I use PHP every day, but as explained most PHP-developers will have problems and I can say that, because I've more than 20 years experience in that. Do you have that? http://en.wikipedia.org/wiki/Appeal_to_authority I'm just wondering... for whom is PHP developed, for the PHP-internals

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Sherif Ramadan wrote: ... I have no problem with it, I use PHP every day, but as explained most PHP-developers will have problems and I can say that, because I've more than 20 years experience in that. Do you have that? 20 years experience in PHP? No, I believe it only ever appeared

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 15:19, Lester Caine wrote: Sherif Ramadan wrote: ... I have no problem with it, I use PHP every day, but as explained most PHP-developers will have problems and I can say that, because I've more than 20 years experience in that. Do you have that? 20 years experience in PHP? No,

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Andrew Faulds wrote: I top you 20 years with 37 years. I was programming in Algol in 1975 ( at Warwick university ). I'm not a programmer, I'm a hardware engineer who has to program to make systems work. I added PHP 12 years ago to create web based applications to augment c and Pascal based

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 16:11, Lester Caine wrote: Andrew Faulds wrote: I top you 20 years with 37 years. I was programming in Algol in 1975 ( at Warwick university ). I'm not a programmer, I'm a hardware engineer who has to program to make systems work. I added PHP 12 years ago to create web based

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Ferenc Kovacs tyr...@gmail.com: more than 20 years experience in that. Do you have that? http://en.wikipedia.org/wiki/Appeal_to_authority So what? U are using Wikipedia to invalidate me. :) shrug Is it so bad to hear an people with more experience? Do you have problems with it with

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Andrew Faulds wrote: Boo hoo, PHP has new features, you'll have to understand them, shock horror! Actually I've not even look at some of these newfangled bits, and if they did appear in one of my key libraries then I'd definitely fork a version and maintain my own copy! I'm STILL trying to

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Ferenc Kovacs
On Wed, Jul 25, 2012 at 5:11 PM, Lester Caine les...@lsces.co.uk wrote: Andrew Faulds wrote: I top you 20 years with 37 years. I was programming in Algol in 1975 ( at Warwick university ). I'm not a programmer, I'm a hardware engineer who has to program to make systems work. I added PHP 12

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 16:37, Alex Aulbach wrote: 2012/7/25 Ferenc Kovacs tyr...@gmail.com: more than 20 years experience in that. Do you have that? http://en.wikipedia.org/wiki/Appeal_to_authority So what? U are using Wikipedia to invalidate me. :) shrug Is it so bad to hear an people with more

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Andrew Faulds a...@ajf.me: We, of course, should try to avoid user confusion if it will be a big issue. But I don't see any here. I said it's small and the fix is small also. Big issue, big fix, small issue, small fix. Understand? Also, 20 years experience does not necessarily a

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Ferenc Kovacs
He linked to the Wikipedia Appeal to authority article because it's a common logical fallacy. Experience alone does not make you any more right than somebody else, and in the same way, someone without it is not less right. Also, I have 16 years of experience at life, so obviously I'm an

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 16:43, Alex Aulbach wrote: 2012/7/25 Andrew Faulds a...@ajf.me: We, of course, should try to avoid user confusion if it will be a big issue. But I don't see any here. I said it's small and the fix is small also. Big issue, big fix, small issue, small fix. Understand? Also, 20

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 16:47, Ferenc Kovacs wrote: He linked to the Wikipedia Appeal to authority article because it's a common logical fallacy. Experience alone does not make you any more right than somebody else, and in the same way, someone without it is not less right. Also, I

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Ferenc Kovacs
On Wed, Jul 25, 2012 at 5:37 PM, Alex Aulbach alex.aulb...@gmail.comwrote: 2012/7/25 Ferenc Kovacs tyr...@gmail.com: more than 20 years experience in that. Do you have that? http://en.wikipedia.org/wiki/Appeal_to_authority So what? U are using Wikipedia to invalidate me. :) shrug Is it

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 16:51, Ferenc Kovacs wrote: On Wed, Jul 25, 2012 at 5:37 PM, Alex Aulbach alex.aulb...@gmail.com mailto:alex.aulb...@gmail.com wrote: 2012/7/25 Ferenc Kovacs tyr...@gmail.com mailto:tyr...@gmail.com: more than 20 years experience in that. Do you have that?

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Thomas Hruska
On 7/25/2012 7:50 AM, Andrew Faulds wrote: On 25/07/12 15:19, Lester Caine wrote: Sherif Ramadan wrote: ... I have no problem with it, I use PHP every day, but as explained most PHP-developers will have problems and I can say that, because I've more than 20 years experience in that. Do you

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Ferenc Kovacs wrote: some/most of the E_STRICT messages are telling you about (possible) problems in your code. The major hurdle here is 'static', and not being able to use a function both statically or with $this. PEAR is currently throwing these 'warnings' so is there problems in the PEAR

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 17:09, Lester Caine wrote: Ferenc Kovacs wrote: some/most of the E_STRICT messages are telling you about (possible) problems in your code. The major hurdle here is 'static', and not being able to use a function both statically or with $this. PEAR is currently throwing these

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Andrew Faulds wrote: Do you use PHP objects and classes at all? Because if you do, then your PHP5 code SHOULDN'T work in PHP4. Perhaps it does, but I find that very suspicious. And you shouldn't rely on it. http://lsces.org.uk/hg/ https://github.com/bitweaver http://cia.vc/stats/author/lsces

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Andrew Faulds a...@ajf.me: Experience can be helpful. But you must support things with facts Ok, I tried to bring all the pro arguments together. Suggestion: For a generator, rename the keyword function to ... generator or something like that. Example: generator hugo() {

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 17:54, Alex Aulbach wrote: 2012/7/25 Andrew Faulds a...@ajf.me: Experience can be helpful. But you must support things with facts Ok, I tried to bring all the pro arguments together. Suggestion: For a generator, rename the keyword function to ... generator or something like that.

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Dave Ingram
Fact: Adding a new name for a special kind of function as a syntax construct is going to cost (possibly unnecessary) time and energy, because now you have functions, and weird things that look almost like functions but aren't and can only be used to make generators. Just to put my oar in too,

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Andrew Faulds
On 25/07/12 18:58, Dave Ingram wrote: Fact: Adding a new name for a special kind of function as a syntax construct is going to cost (possibly unnecessary) time and energy, because now you have functions, and weird things that look almost like functions but aren't and can only be used to make

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Nikita Popov
Just please don't forget that generator isn't quite a rare word (unlike yield), so there are high chances for collisions (in particular with namespaced code). So if you have some kind of Code\Generator class, you're screwed. Keywords don't grow on trees, you know ;) Also I'd like to point out

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Lester Caine wrote: Do you use PHP objects and classes at all? Because if you do, then your PHP5 code SHOULDN'T work in PHP4. Perhaps it does, but I find that very suspicious. And you shouldn't rely on it. http://lsces.org.uk/hg/ https://github.com/bitweaver http://cia.vc/stats/author/lsces I

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Stas Malyshev
Hi! Speaking of parse errors, I'm having trouble parsing this line. I *think* you're saying that generators are just complex things and that's the way it should be. I... guess I agree, though I have a lower opinion on the complexity of generators. Seem like a fairly straightforward concept

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Lester Caine
Sara Golemon wrote: Fact: yield makes functions some kind of different. Yes, they turn normal functions into continuation functions (functions which can be exited and reentered dynamically). But WHY would you not simply put the function that is handling the returned data in place of the

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Sara Golemon
Suggestion: For a generator, rename the keyword function to ... generator or something like that. Example: generator hugo() { yield ... } As Nikita pointed out, having a T_GENERATOR token will cause side-effect problems from namespace collisions. This is a concern any

RE: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Jared Williams
-Original Message- From: Nikita Popov [mailto:nikita@gmail.com] Sent: 22 July 2012 16:53 To: Jared Williams Cc: Nikita Popov; PHP internals Subject: Re: [PHP-DEV] Re: Generators in PHP On Sat, Jul 21, 2012 at 6:31 PM, Jared Williams jared.willia...@ntlworld.com wrote

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Nikita Popov nikita@gmail.com: particular with namespaced code). So if you have some kind of Code\Generator class, you're screwed. Keywords don't grow on trees, you know ;) Hm. Ok, thats a problem. Oh, man, do I really have to find a good keyword myself? Maybe we should use a

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Alex Aulbach
2012/7/25 Sara Golemon poll...@php.net: Fact: yield/generators is more or less complicated, this shouldn't be changed - it's a proven concept. Speaking of parse errors, I'm having trouble parsing this line. I *think* you're saying that generators are just complex things and that's the way it

Re: [PHP-DEV] Re: Generators in PHP

2012-07-25 Thread Rasmus Lerdorf
On 07/25/2012 04:25 PM, Alex Aulbach wrote: In 50 lines of code yield will be just overseen. But I meant something different: I thought of documentation. Maybe someone reads the docs. Really! In the docs he will find functions. And in the function this yield. He dosn't want to know that. It

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Alex Aulbach
2012/7/23 Sara Golemon poll...@php.net: Curious if you could expand on that. Generators are iterators, so not sure what you're asking for. It's the point which is unlogical for me. Maybe it's a question. If the generator is an object with the implementation of an iterator, why do we need to

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Andrew Faulds
On 24/07/12 18:34, Alex Aulbach wrote: 2012/7/23 Sara Golemon poll...@php.net: Curious if you could expand on that. Generators are iterators, so not sure what you're asking for. It's the point which is unlogical for me. Maybe it's a question. If the generator is an object with the

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Yahav Gindi Bar
On 24 ביול 2012, at 20:35, Andrew Faulds wrote: On 24/07/12 18:34, Alex Aulbach wrote: 2012/7/23 Sara Golemon poll...@php.net: Curious if you could expand on that. Generators are iterators, so not sure what you're asking for. It's the point which is unlogical for me. Maybe it's a question.

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Alex Aulbach
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

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Andrew Faulds
On 24/07/12 18: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 -

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Yahav Gindi Bar
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

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Andrew Faulds
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

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Alex Aulbach
2012/7/24 Andrew Faulds a...@ajf.me: But PHP functions usually have side-effects, they aren't strict mathematical functions. Ah, you might mean str_tok()? Are there more, do you have a list? But we're in PHP-programming-context. You write a function in PHP, you call it and it will return once

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Andrew Faulds
On 24/07/12 19:32, Alex Aulbach wrote: 2012/7/24 Andrew Faulds a...@ajf.me: But PHP functions usually have side-effects, they aren't strict mathematical functions. Ah, you might mean str_tok()? Are there more, do you have a list? But we're in PHP-programming-context. You write a function in

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Gustavo Lopes
Em Tue, 24 Jul 2012 19:56:46 +0200, Alex Aulbach alex.aulb...@gmail.com escreveu: 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

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Alex Aulbach
2012/7/24 Andrew Faulds a...@ajf.me: PHP is not LISP. Hey, I don't want to have LISP. I just want to make complicated things more clear, and it doesn't matter, if something else is right or wrong in the past. It isn't difficult to make a new keyword or something wich disticts it a little bit

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Alex Aulbach
2012/7/24 Gustavo Lopes glo...@nebm.ist.utl.pt: When you have function foo() { ... yield /* ... */; ... } and you call foo(), you get the same thing every time: a Generator object. It so happens that the implementation of that object is inside the body of the function. Hmmm. It's not that I

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Andrew Faulds
On 24/07/12 20:13, Alex Aulbach wrote: 2012/7/24 Gustavo Lopes glo...@nebm.ist.utl.pt: When you have function foo() { ... yield /* ... */; ... } and you call foo(), you get the same thing every time: a Generator object. It so happens that the implementation of that object is inside the body of

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Sara Golemon
Or when you have programming errors, when you write function blubb() { ... yields... ... ... return } (you may only see the return). But that's okay, because PHP *does* see both, and it tells you yield may not be used with return in a lovely little parser error. Some developers

Re: [PHP-DEV] Re: Generators in PHP

2012-07-24 Thread Sherif Ramadan
On 24/07/12 19:32, Alex Aulbach wrote: 2012/7/24 Andrew Faulds a...@ajf.me: But PHP functions usually have side-effects, they aren't strict mathematical functions. Ah, you might mean str_tok()? Are there more, do you have a list? But we're in PHP-programming-context. You write a

Re: [PHP-DEV] Re: Generators in PHP

2012-07-23 Thread Sara Golemon
My first thought was how could someone reading the code see, that it is a generator? Somewhat snarky answer: By documenting the code in the first place. Yeah, I know, we all inherit other people's code and the other person never writes comments. I don't think this is as big of a problem in

Re: [PHP-DEV] Re: Generators in PHP

2012-07-22 Thread Nikita Popov
On Sat, Jul 21, 2012 at 6:31 PM, Jared Williams jared.willia...@ntlworld.com wrote: Can't yield a reference to an array item directly. Eg. function map(array $row) { yield $row[0]; } Thanks, this is fixed now. Also seems to be a problem with iterating foreach(map($row) as $value)

Re: [PHP-DEV] Re: Generators in PHP

2012-07-22 Thread Alex Aulbach
2012/7/20 Nikita Popov nikita@gmail.com: On Tue, Jun 5, 2012 at 7:35 PM, Nikita Popov nikita@googlemail.com wrote: Hi internals! The implementation is outlined in the RFC-stub here: https://wiki.php.net/rfc/generators A small progress update on this: * Generators are now

RE: [PHP-DEV] Re: Generators in PHP

2012-07-21 Thread Jared Williams
-Original Message- From: Nikita Popov [mailto:nikita@gmail.com] Sent: 20 July 2012 21:46 To: Nikita Popov Cc: PHP internals Subject: [PHP-DEV] Re: Generators in PHP On Tue, Jun 5, 2012 at 7:35 PM, Nikita Popov nikita@googlemail.com wrote: Hi internals