I'm not understanding how inlining a closure expression could help reduce the 
burden of saving state to a temporary variable and then restoring it after 
execution, unless there was some additional AST processing.

macro method take 2:

class Foo {
  def bar() {
    push { field1 = value, field2 ->
     baz()
    }
  }
}

macro method take 1 -- I think this would have better IDE support:

class Foo {
  def bar() {
    push (field1 = value, field2) {
      baz()
    }
  }
}



An alternative to the macro method would be a local transform.  A variable 
declaration would allow an annotation.  So maybe something like this could be a 
more general capture-restore:

@CaptureRestore({ -> ... })
def (one, two) = [field1 = value, field2] // maybe "_" or something would 
prevent the need for typing temp var names.

converts to

def one = field1
def two = field2
one = value
try {
  ...
} finally {
  field1 = one
  field2 = two
}


This idea has the code to execute come before the state capture and update, 
which is not the best IMO.  Especially if "..." represents a lot of code.  To 
flip it, the closure could be assigned to something:
@CaptureRestore({ field1 = value, field2 })
def ___ = { ->
   ...
}

Reply via email to