Re: D equivalent of Python's try..else

2015-11-22 Thread rsw0x via Digitalmars-d-learn
On Sunday, 22 November 2015 at 10:01:48 UTC, Kagamin wrote: As an idiomatic option there can be `finally(exit)`, `finally(success)` and `finally(failure)` that would mirror semantics of scope guards. how does this differ from just putting a scope(failure) inside the try block? it only trigger

Re: D equivalent of Python's try..else

2015-11-22 Thread Kagamin via Digitalmars-d-learn
As an idiomatic option there can be `finally(exit)`, `finally(success)` and `finally(failure)` that would mirror semantics of scope guards.

Re: D equivalent of Python's try..else

2015-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, November 22, 2015 07:41:40 Mike Parker via Digitalmars-d-learn wrote: > On Saturday, 21 November 2015 at 13:57:01 UTC, Shriramana Sharma > wrote: > > > > Hmm – I forgot Python has `else` for `for` and `while` too. But > > it's a tad difficult to wrap one's mind around the meaning of > >

Re: D equivalent of Python's try..else

2015-11-22 Thread Kagamin via Digitalmars-d-learn
On Saturday, 21 November 2015 at 13:57:01 UTC, Shriramana Sharma wrote: Hmm – I forgot Python has `else` for `for` and `while` too. But it's a tad difficult to wrap one's mind around the meaning of the word `else` in this particular context whereas it actually means `nobreak`. In a way `for`

Re: D equivalent of Python's try..else

2015-11-21 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 21 November 2015 at 13:57:01 UTC, Shriramana Sharma wrote: Hmm – I forgot Python has `else` for `for` and `while` too. But it's a tad difficult to wrap one's mind around the meaning of the word `else` in this particular context whereas it actually means `nobreak`. Perhaps if this

Re: D equivalent of Python's try..else

2015-11-21 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2015-11-21 at 19:26 +0530, Shriramana Sharma via Digitalmars-d- learn wrote: > […] > Hmm – I forgot Python has `else` for `for` and `while` too. But it's > a tad > difficult to wrap one's mind around the meaning of the word `else` in > this > particular context whereas it actually means

Re: D equivalent of Python's try..else

2015-11-21 Thread Shriramana Sharma via Digitalmars-d-learn
Russel Winder via Digitalmars-d-learn wrote: > else on for and while, whilst technically redundant as well, does > occasionally make for a nicer read, for very analogous reasons. It can > generally avoid the need for extra booleans and other state variables. Hmm – I forgot Python has `else` for `

Re: D equivalent of Python's try..else

2015-11-21 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2015-11-20 at 22:39 -0800, Ali Çehreli via Digitalmars-d-learn wrote: > […] > I don't know what idiom that enables in Python but it feels to me > like > putting the statements right after the ones that could throw suffices > in > D (and Python): The else clause for while, for, try, has

Re: D equivalent of Python's try..else

2015-11-20 Thread Ali Çehreli via Digitalmars-d-learn
On 11/20/2015 09:45 PM, Shriramana Sharma wrote: Hello. In Python one has the syntax try..except..else.. where code in the else clause will only be executed if an exception does not occur. (Ref: http://stackoverflow.com/a/22579805/1503120) In D, is there such an idiomatic/canonical construct? Th

Re: D equivalent of Python's try..else

2015-11-20 Thread rsw0x via Digitalmars-d-learn
On Saturday, 21 November 2015 at 05:55:53 UTC, Shriramana Sharma wrote: rsw0x wrote: scope(failure) can be used to run code when an exception is thrown inside the scope, and scope(success) only triggers if the scope exited successfully http://ddili.org/ders/d.en/scope.html Thanks but I kno

Re: D equivalent of Python's try..else

2015-11-20 Thread Shriramana Sharma via Digitalmars-d-learn
Shriramana Sharma wrote: > In Python one has the syntax try..except..else.. where code in the > else clause will only be executed if an exception does not occur. (Ref: > http://stackoverflow.com/a/22579805/1503120) Official Python documentation: https://docs.python.org/3/reference/compound_stmts

Re: D equivalent of Python's try..else

2015-11-20 Thread Shriramana Sharma via Digitalmars-d-learn
rsw0x wrote: > scope(failure) can be used to run code when an exception is > thrown inside the scope, and scope(success) only triggers if the > scope exited successfully > > http://ddili.org/ders/d.en/scope.html Thanks but I know that and it executes only at the point of scope exit. But I want

Re: D equivalent of Python's try..else

2015-11-20 Thread rsw0x via Digitalmars-d-learn
On Saturday, 21 November 2015 at 05:45:37 UTC, Shriramana Sharma wrote: Hello. In Python one has the syntax try..except..else.. where code in the else clause will only be executed if an exception does not occur. (Ref: http://stackoverflow.com/a/22579805/1503120) In D, is there such an idiomat