As other users (see comp.lang.rexx/2005-11/msg00065.html), I use sometimes a function iif which on the basis of a condition selects between two values :
iif:
use strict arg condition, iftrue, iffalse
if condition then
interpret "return" iftrue
else
interpret "return" iffalse
I see two drawbacks with this function :
The caller must surround the 2nd and 3rd argument by quotes, to pass a string to the function. Example : say iif(s == .nil, 's', 's~id')
The whole scope of the caller must be visible, to let the evaluation have access to all the variables of the caller. So I can't implement this function as a procedure or a routine or a method. And I can't put it in my library that I requires from my scripts.
I had a look at the function RexxActivation::run (putting a breakpoint here is very instructive).
I see that each instruction is evaluated by : nextInst->execute(this, localStack)
It seems that each instruction is in charge of the evaluation of its arguments, using : this->_expression_->evaluate(context, stack)
Could we imagine that such a behavior is possible at the level of user rexx code ? The not-evaluated-_expression_ passed to the rexx code should bring the context and stack with her, to let the user write
_expression_->evaluate()
A not-evaluated-_expression_ is not of type String. Should be of a new type (Closure ?) which supports the method evaluate().
Example :
iif: procedure
use unevaluated arg condition, iftrue, iffalse
if condition->evaluate() then
return iftrue->evaluate()
else
return iffalse->evaluate()
Here " unevaluated " is a keyword to indicate the deferred evaluation of the arguments.
I can use a procedure or routine or method since the evaluation of the _expression_ is done in the caller's context.
The caller calls the function without surrounding the expressions in quotes :
say iif(s == .nil, s, s~id)
And there is no error like Object "The NIL object" does not understand message "ID" when s is nil.
Jean Louis
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ Oorexx-devel mailing list Oorexx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/oorexx-devel