Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Object REXX
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Procedure and function === ooRexx provides a new way to define procedures and functions that are not specific to a particular class by using the <code>::ROUTINE</code> [[Object REXX#Instructions|directive]]; unlike the older <code>PROCEDURE</code>, code defined with <code>::ROUTINE</code> has an implicit <code>RETURN</code> at the end. The <code>CALL</code> instruction can be used to invoke a routine as a procedure. In addition, routines that return values via the <code>RETURN</code> keyword instructions can be called using function calls by specifying the name of the routine followed by parentheses. The content within the brackets is passed as an argument to a routine. While the <code>PARSE ARG</code> instruction can be used to parse received string arguments and assign them to variables, the newer <code>USE ARG</code> must be used for objects of other types. In addition, the <code>STRICT</code> option can be used to limit the number of arguments that must match the number of specified names.<ref name=":2" /><syntaxhighlight lang="oorexx" style="background-color: #ffffff; !important" line="1">call DoSomething /* "CALL" keyword instruction */ table = .stem~new /* Stem object for indsum */ table[1] = 2; table[2] = 4 say indsum{table,1.2) /* function call requiring use arg */ say dirsum(2,4) /* either parse arge or use arg okay */ ::Routine DoSomething /* "ROUTINE" directive (procedure) */ say "I did something!" /* output: I did something! */ /* Implicit return because next */ /* statement is a directive. */ ::Routine dirsum /* "ROUTINE" directive (function) */ parse arg first, second /* Valid because both are strings. */ return first+second ::Routine indsum /* "ROUTINE" directive (function) */ use strict arg table, first, second /* can't use parse arg with stem arg */ Sum = table{first} + table[second] /* do calculation */ return Sum /* "RETURN" result */</syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)