PROPOSAL - 'uplevel' in 'proc' → missing more general 'macro'-solution

from comp.lang.tcl

an uplevel-proc is a proc which evaluate the entire content uplevel → example:

  proc Format_Return_Error_Check {hdl err} {
    uplevel "Format_Error_Check $hdl $err ; set retM void"
  }

This simulate a CPP-Macro like behavior in tcl.

The easy solution to just a proc-body like function:

  proc Format_Return_Error_Check {hdl err} {
    upvar retM retM
    Format_Error_Check $hdl $err
    set retM void
  }

is not really a solution because the "upvar" in a sub-proc like Format_Error_Check is broken because Format_Return_Error_Check return an extra call-frame.

solution:

It should be possible to create a proc witch not add an extra level to the call-frame, a good name would be macro :

  macro Format_Return_Error_Check {hdl err} {
    Format_Error_Check $hdl $err
    set retM void
  }

The following features should be present:

  1. The macro argument variable (hdl err) is only visible in the macro-frame
  2. The other variable (retM) is from the calling-frame
  3. The macro does NOT add a call-frame → an upvar in Format_Error_Check should call he calling-frame and not the macro-frame
  4. The new local keyword add a variable only to the macro-frame
  5. The global or variable keyword add a variable to the macro-frame