Re: [PHP-DEV] Re: 回复: [PHP-DEV] resume after exception

2012-04-06 Thread Anthony Ferrara
Rasmus, I think you're missing the difference here. Let's look at an exception. try { doFoo(); throwsException(); doBar(); } catch (Exception $e) { doBaz(); } This is NOT the same as: doFoo(); throwsException('doBaz'); doBar(); To emulate the exception using continuation passi

Re: [PHP-DEV] Re: 回复: [PHP-DEV] resume after exception

2012-04-06 Thread Rasmus Schultz
2012/4/5 Anthony Ferrara : > Why not just do: > > function foo(callable $callback) { >    $a = 0; >    $callback(); >    $a = 1; >    $callback(); > } > > function bar() { >    foo(function() { echo 1; }); > } > > It's functionally the same, but doesn't have the stack magic. > > Now, it won't be ab

Re: [PHP-DEV] resume after exception

2012-04-05 Thread Galen Wright-Watson
On Thu, Apr 5, 2012 at 4:47 PM, Stas Malyshev wrote: > > However, in general, thinking about more complex flow control structures > in fine. Just there's no reason to get exceptions mixed into it. > > Agreed. While restarting and resuming after exceptions could be useful, and a condition signaling

Re: [PHP-DEV] resume after exception

2012-04-05 Thread Stas Malyshev
Hi! >> While exceptions themselves may not be suitable for a general-purpose > control structure, they do embody one. It's an early-return mechanism that > you also see in some of the other control structures mentioned in this > thread (Python's generators, Common LISP's conditions). Even the "ret

Re: [PHP-DEV] resume after exception

2012-04-05 Thread Galen Wright-Watson
2012/4/5 Stas Malyshev > Hi! > > >> it's a wonderful mechanism with more uses than simply reporting errors > >> - the aspect of transferring control is what I find really interesting > >> about exceptions. > > Exceptions should not be used for flow control. [...] > > While exceptions themselves m

Re: [PHP-DEV] resume after exception

2012-04-05 Thread Stas Malyshev
Hi! >> it's a wonderful mechanism with more uses than simply reporting errors >> - the aspect of transferring control is what I find really interesting >> about exceptions. Exceptions should not be used for flow control. They are called "exceptions" for a reason - to signify that something unusua

Re: [PHP-DEV] Re: 回复: [PHP-DEV] resume after exception

2012-04-05 Thread Anthony Ferrara
Rasmus, What would that give you that a continuation passing paradigm wouldn't? Why not tell the code what to call before you call it, rather than bubbling up the stack (which then forces a fork of the stack, as you need to partially unwind it, but keep track of what you unwound for the resume).

[PHP-DEV] Re: 回复: [PHP-DEV] resume after exception

2012-04-05 Thread Rasmus Schultz
interesting, but this doesn't have anything in particular to do with what I was talking about. to the best of my understanding, an exception transfers control back to the nearest calling code that has declared it is ready/willing/able to resume control in the event that, somewhere up the call-stac

Re: [PHP-DEV] resume after exception

2012-04-03 Thread Anthony Ferrara
Sam, Just to be clear, I wasn't opposing pythonic generators. I was opposing using this feature for that purpose. If we wanted generators, I would suggest implementing them fully (as in adding a `yield` statement). However, that's not going to be as easy as it sounds, since what would happen wi

Re: [PHP-DEV] 回复: [PHP-DEV] resume after exception

2012-04-03 Thread Kiall Mac Innes
Retry is a feature I would very much like to see... While it's not stritcly necessary to implement in core, it makes the code much cleaner.. Thanks, Kiall Sent from my phone. On Apr 3, 2012 8:28 a.m., "reeze" wrote: > If just for exception recovery how about implement ruby's retry ? > > http:/

[PHP-DEV] 回复: [PHP-DEV] resume after exception

2012-04-03 Thread reeze
If just for exception recovery how about implement ruby's retry ? http://www.tutorialspoint.com/ruby/ruby_loops.htm Ruby retry statement section. 在 2012年4月2日星期一,下午8:44,Rasmus Schultz 写道: > I was just reading about the new async/await keywords in C# 5.0, and while > this has no particular re

Re: [PHP-DEV] resume after exception

2012-04-03 Thread Sebastian Bergmann
On 04/02/2012 09:40 PM, Johannes Schlüter wrote: I fear this brings hardly understandable code flows. I second that emotion. -- Sebastian BergmannCo-Founder and Principal Consultant http://sebastian-bergmann.de/ http://thePHP.cc/ -- PHP Internals

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Charlie Somerville
Magnus Holm has an excellent proof of concept for this in Ruby, which supports continuations: http://timelessrepo.com/never-gonna-let-you-go On Apr 2, 2012 10:44 PM, "Rasmus Schultz" wrote: > I was just reading about the new async/await keywords in C# 5.0, and while > this has no particular rele

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Samuel Giles
Sorry, as an add on to my previous, a feature request was opened on the Bug tracker in 2010 #51460 for a yield syntax construct Sam. On Mon, Apr 2, 2012 at 10:51 PM, Samuel Giles wrote: > Hi Anthony, > > Ok, I see that now. I know you're not necessarily sa

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Samuel Giles
Hi Anthony, Ok, I see that now. I know you're not necessarily saying what's been proposed is a good idea but I can see a benefit in pythonic style generators as a separate piece of functionality, implementing a yield function, has this ever been discussed before? My apologies if this is the case I

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Anthony Ferrara
Sam, I'm not saying it's a good idea, but this would allow for pythonic style generators. http://wiki.python.org/moin/Generators Just pointing out one potential use-case... Anthony On Mon, Apr 2, 2012 at 4:35 PM, Samuel Giles wrote: > Hi Internals > > function test() >> { >>  echo "Begin Test

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Samuel Giles
Hi Internals function test() > { > echo "Begin Test!\n"; > > throw new Interrupt(); > > echo "Execution resumed!"; > } > > try > { > test(); > } > catch (Interrupt $e) > { > echo "Execution interrupted.\n"; > resume; > } > > The output of this would be: > > Begin Test! > Execution interrupte

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Johannes Schlüter
On Tue, 2012-04-03 at 00:49 +0500, Alexey Shein wrote: > 3 апреля 2012 г. 0:40 пользователь Johannes Schlüter > написал: > > On Mon, 2012-04-02 at 08:44 -0400, Rasmus Schultz wrote: > >> I was just reading about the new async/await keywords in C# 5.0, and while > >> this has no particular relevanc

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Galen Wright-Watson
On Mon, Apr 2, 2012 at 5:44 AM, Rasmus Schultz wrote: > I was just reading about the new async/await keywords in C# 5.0, and while > this has no particular relevance to PHP as such, it got me thinking about > this idea... > > What if you could resume execution after an exception was thrown? > > T

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Alexey Shein
3 апреля 2012 г. 0:40 пользователь Johannes Schlüter написал: > On Mon, 2012-04-02 at 08:44 -0400, Rasmus Schultz wrote: >> I was just reading about the new async/await keywords in C# 5.0, and while >> this has no particular relevance to PHP as such, it got me thinking about >> this idea... >> >>

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Johannes Schlüter
On Mon, 2012-04-02 at 08:44 -0400, Rasmus Schultz wrote: > I was just reading about the new async/await keywords in C# 5.0, and while > this has no particular relevance to PHP as such, it got me thinking about > this idea... > > What if you could resume execution after an exception was thrown? So

Re: [PHP-DEV] resume after exception

2012-04-02 Thread Ivan Enderlin @ Hoa
Hi Rasmus, On 02/04/12 14:44, Rasmus Schultz wrote: I was just reading about the new async/await keywords in C# 5.0, and while this has no particular relevance to PHP as such, it got me thinking about this idea... What if you could resume execution after an exception was thrown? Fictive examp

[PHP-DEV] resume after exception

2012-04-02 Thread Rasmus Schultz
I was just reading about the new async/await keywords in C# 5.0, and while this has no particular relevance to PHP as such, it got me thinking about this idea... What if you could resume execution after an exception was thrown? Fictive example: function test() { echo "Begin Test!\n"; throw