Now that the ADDRESS WITH activity is moving along somewhat, I thought I
might revisit an idea that has been kicking around since the early days of
the project. This was a question of allowing some form of call-by-name to
the language.

I've been mulling this over for some time and decided it was finally time
to take a crack at it. It turned out to be not that tough with the current
state of the code. This would not have been possible 14 years ago.

Anyway, the additions to the language are

1) A new class called VariableReference, which has methods NAME, VALUE, and
SETVALUE.  This class gives access to variables that can be passed around.
2) A new prefix operator, '&' that creates a reference to a variable that
follows it. Only simple and stem variables are support (i.e., non
compound). This operator is the only way to create a variable reference.
3) An equivalent change to USE ARG to allow matching up a local variable
name to a variable reference, creating an alias to the original variable.

call foo &a

::routine foo
  use arg &var

creates the alias and changes made to VAR in routine FOO are really changes
made to variable A in the caller.

 Note that arguments marked with & on USE ARG are always required and the
variable types must always be a match (that is, simple-to-simple or

4) Support in the APIs for passing VariableReferences as arguments (again,
these are never allowed to be optional), invoking the 3 methods on the
reference, and also an API for the method context for creating a reference
object to an Object variable that can be passed as an argument.

I'm a little torn over whether this is needed or not, but the fact that
people keep trying to do this via USE ARG argues there is demand for some
sort of call-by-name capability. Anyway, the prototype appears to be
working, though there are a few more tests that need to be written. This
can be built and played with.

Check out the vibrant tech community on one of the world's most
engaging tech sites,!
Oorexx-devel mailing list

Reply via email to