[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-apl] Feature request: UNWIND-PROTECT-like feature
From: |
David B. Lamkins |
Subject: |
Re: [Bug-apl] Feature request: UNWIND-PROTECT-like feature |
Date: |
Mon, 21 Apr 2014 08:26:59 -0700 |
On Mon, 2014-04-21 at 17:34 +0800, Elias Mårtenson wrote:
> We need a feature similar to the Common Lisp form UNWIND-PROTECT, or
> in Java: try/finally.
>
>
> For those who don't know, this form allows you to execute code after
> some code has been run, regardless of how the latter exits (return
> normally, exited with error, etc...)
>
>
> What I envision is something like this:
>
>
> {2÷0} ⎕UnwindProtect {⎕←'hello'}
>
>
>
> This code would print "hello" even though the left-hand expression
> yielded an error.
>
>
> I'd also like to see some information regarding the nature of the exit
> (return value of the left-hand form or error information) passed along
> in ⍵ and ⍺ to the right-hand function.
>
>
> A construct like this is necessary to create safe forms for dealing
> with, for example, SQL transactions safely. It will also be needed in
> the file utility library that I will be writing.
>
>
> I could, of course, implement this as a native library but I feel this
> is a feature that belongs in the core (since it's so important).
See quad-EA (execute alternate). That does almost the same thing, except
that the order of arguments is reversed (in keeping with APL's
right-to-left flow) and the arguments are quoted rather than in lambdas.
I'm using quad-EA in the transaction wrapper in my component-file
implementation.