On 21.11.20 20:29, Milles, Eric (TR Technology) wrote:
[...]
I was thinking of something like this so as not to overload the try keyword:
class Foo {
def bar() {
push (field1 = value, field2) { // AST would be re-written to
try/finally like Scenario 1/2
baz()
}
}
...
}
how about
class Foo {
def withState(tryState, code) {
def finalState = state
try {
state = tryState
code.call()
} finally {
state = finalState
}
}
....
def bar(){
withState(value) {
baz()
}
}
}
could be a mixin... but if your requirement is to avoid the creation of
additional objects, then this will not work, as the Closure will be
created new every time. And then a macro would be indeed better.
bye jochen