The interpret instruction processes the content of the sourceExpression as though it were a sequence of Rexx instructions that were implanted in the current source program at the position of the interpret instruction. The sourceExpression is evaluated using normal expression capabilities. The resulting value can contain multiple instructions that are separated by semicolons.
The need for the interpret instruction can often be replaced by using the value built-in function instead.
The interpret instruction is a very powerful capability! There are several restrictions.
Note: you can interpret another interpret instruction within the result of the sourceExpression !
Here is an introductory example, that invokes one of three subroutines dynamically.
/* switchasub.rex */ parse arg n . if \ datatype( n, wholenumber ) then signal usagemsg if n < 1 | n > 3 then signal usagemsg interpret 'call sub'n /* call subroutine n ! */ return result sub1 : procedure say 'one' return 1 sub2 : procedure say 'two' return 2 sub3 : procedure say 'three' return 3 usagemsg : say 'you did not enter a numeric value between 1 and 3' say 'usage:' say ' rexx switchasub wholeNumber' exit 99