inner functions instead of scope
Marc Schütz via Digitalmars-d
digitalmars-d at puremagic.com
Thu May 26 01:44:29 PDT 2016
On Tuesday, 24 May 2016 at 02:01:14 UTC, cy wrote:
> void transaction(Callable)(Callable do_stuff)
^^^^^^^^
`scope` to avoid GC
> if(isCallable(Callable)) {
> begin();
> scope(failure) rollback();
> scope(success) commit();
> do_stuff();
> }
>
> ...
>
> transaction({
> big_long_complicated_code_block();
> });
This technique is very widely used in Ruby, and I agree that it's
really useful. It would be even nicer if we had trailing
delegates, as Jacob Carlborg suggested [1]:
db.transaction {
// ...
}
[1] http://forum.dlang.org/post/modnbn$184o$1@digitalmars.com
More information about the Digitalmars-d
mailing list