Statement, Routine (Procedure, Function), "Stem"-Variable
CALL-statements (invoking procedures)
Function invocations
SIGNAL-statements (like a "GOTO" instruction in other languages)
Exception handling (SIGNAL ON resp. CALL ON)
Output:
Oho! 1
C'est la fin!/* A Rexx-Programm with an internal routine named 'TIMESTAMP' */
CALL TimeStamp /* call a subroutine */
CALL SysSleep 5 /* sleep 5 seconds */
CALL TimeStamp /* call a subroutine */
EXIT /* exit program */
TimeStamp : /* label */
SAY "It is rather late ..."
RETURN
Output:
Invocation: the name (label), immediately followed by a left and right parenthesis
The return value ("function value") replaces the invocation
Invocation: CALL followed by the name (label) of the routine
Interpreter stores the return value in the special variable RESULT
/* A Rexx-Programm with an internal function named 'TIMESTAMP' */
SAY TimeStamp() /* function call */
CALL SysSleep 5 /* sleep 5 seconds */
CALL TimeStamp /* procedure call */
SAY result /* show function value */
EXIT /* exit program */
TimeStamp : /* label */
RETURN "It is rather late ..."
Output:
0 (zero) indicates that the external command completed without any errors or failuresABBREV()ABS()ADDRESS()ARG()B2X()BEEP()BITAND()BITOR()BITXOR()C2D()C2X()CENTER()CHANGESTR()CHARIN()CHAROUT()CHARS()COMPARE()COPIES()COUNTSR()D2C()D2X()DATATYPE()DATE()DELSTR()DELWORD()DIGITS()DIRECTORY()ENDLOCAL()ERRORTEXT()FILESPEC()FORM()FORMAT()FUZZ()INSERT()LASTPOS()LEFT()LENGTH()LINEIN()LINEOUT()LINES()MAX()MIN()OVERLAY()POS()QUEUED()RANDOM()REVERSE()RIGHT()SETLOCAL()SIGN()SOURCELINE()SPACE()STREAM()STRIP()SUBSTR()SUBWORD()SYMBOL()TIME()TRACE()TRANSLATE()TRUNC()VALUE()VAR()VERIFY()WORD()WORDINDEX()WORDLENGTH()WORDPOS()WORDS()X2B()X2C()XRANGE()Loading an external Rexx function package from Rexx, an example
RxMessageBoxRxWinExecSysAddRexxMacroSysBootDriveSysClearRexxMacroSpaceSysClsSysCreatePipeSysCurPosSysCurStateSysDriveInfoSysDriveMapSysDropRexxMacroSysDumpVariablesSysFileCopySysFileDeleteSysFileExistsSysFileMoveSysFileSearchSysFileSystemTypeSysFileTreeSysForkSysFormatMessageSysFromUnicodeSysGetErrorTextSysGetFileDateTimeSysGetKeySysGetMessageSysGetMessageXSysGetShortPathNameSysIniSysIsFileSysIsFileCompressedSysIsFileDirectorySysIsFileEncryptedSysIsFileLinkSysIsFileNotContentIndexedSysIsFileOfflineSysIsFileSparseSearching order for routines
| 1a) | Internal routines (in the program itself) |
| 1b) | Routines defined as directives (in the program itself) |
| 2) | The built-in Rexx routines ("built-in functions (BIF)") |
| 3) | External routines (e.g. Rexx programs) |
It is possible to use the names of the language built-in functions
/* */
SAY date() /* invoke self programmed function below */
SAY "DATE"() /* invoke the Rexx built-in function */
EXIT
DATE : /* "DATE" is in effect a Rexx function ! */
RETURN "Date(), self programmed!"
Output (if run on 2059-05-20):
Date(), self programmed!
20 May 2059
/* */
a = 1
b = 2
SAY "a=" a "b=" b
CALL calc
SAY "a=" a "b=" b
EXIT
calc :
a = a * 2
b = b * 3 / 4
RETURN
Output:
/* */
a = 1
b = 2
SAY "a=" a "b=" b
CALL calc
SAY "a=" a "b=" b
EXIT
calc: PROCEDURE /* no access to global "a" und "b" ! */
a = 5 /* hence, "a" must be defined locally */
b = 6 /* hence, "b" must be defined locally */
a = a * 2
b = b * 3 / 4
RETURN
Output:
/* */
a = 1
b = 2
SAY "a=" a "b=" b
CALL calc
SAY "a=" a "b=" b
EXIT
calc: PROCEDURE EXPOSE b /* no access to "a", but to "b" ! */
a = 5 /* hence, "a" must be defined locally */
a = a * 2
b = b * 3 / 4
RETURN
Output:
Identifier contains one or more dots
The sequence of characters from the beginning up to and including the first dot is called stem (the remainder is called tail)
Output:
stem.0 – stores the total number of "elements"; this allows iterating over all stem entries starting with "1" going up to the number stored in stem.0
Output:
PARSE 1
PARSE statements allow parsing a string and assigning (parts of it) to Rexx variables in one step
Output:
PARSE 2
ruler = COPIES("1234+6789|", 5)
text = " Stiegler Seppl Stumm Zillertal/Tirol"
PARSE VAR text famName firstName rest
SAY ruler; SAY text ; SAY
SAY pp(famName); SAY pp(firstName)
SAY pp(ruler); SAY pp(rest)
EXIT
PP : RETURN "[" || ARG(1) || "]" -- "pretty print" ;)
Output:
1234+6789|1234+6789|1234+6789|1234+6789|1234+6789|
Stiegler Seppl Stumm Zillertal/Tirol
[Stiegler]
[Seppl]
[1234+6789|1234+6789|1234+6789|1234+6789|1234+6789|]
[ Stumm Zillertal/Tirol]
PARSE 3
ruler = COPIES("1234+6789|", 5)
text = " Stiegler Seppl Stumm Zillertal/Tirol"
PARSE VAR text famName firstName rest
SAY ruler; SAY text ; SAY
SAY pp(famName); SAY pp(firstName)
SAY pp(ruler); SAY pp(rest)
EXIT
PP : RETURN "[" || ARG(1) || "]" -- "pretty print" ;)
Output:
1234+6789|1234+6789|1234+6789|1234+6789|1234+6789|
Stiegler Seppl Stumm Zillertal/Tirol
[Stiegler]
[Seppl]
[1234+6789|1234+6789|1234+6789|1234+6789|1234+6789|]
[ Stumm Zillertal/Tirol]
PARSE 4
/* 10 20 30 40
1234+6789|1234+6789|1234+6789|1234+6789| */
text = " Ruaniger Annelle Stumm Zillertal / Tirol "
PARSE VAR text before "/" after
SAY pp(before)
SAY pp(after)
EXIT
PP : RETURN "[" || ARG(1) || "]" -- "pretty print" ;)
Output:
PARSE 5
pattern = "/"
/* 10 20 30 40
1234+6789|1234+6789|1234+6789|1234+6789| */
text = " Ruaniger Annelle Stumm Zillertal / Tirol "
PARSE VAR text before (pattern) after
SAY pp(before)
SAY pp(after)
EXIT
PP : RETURN "[" || ARG(1) || "]" -- "pretty print" ;)
Output:
PARSE 6
/* 10 20 30 40
1234+6789|1234+6789|1234+6789|1234+6789| */
text = " Ruaniger Annelle Stumm Zillertal / Tirol "
PARSE VAR text 3 famName +8 12 firstName city .
SAY pp(famName)
SAY pp(firstName)
SAY pp(city)
EXIT
PP : RETURN "[" || ARG(1) || "]" -- "pretty print" ;)
Output:
PARSE 7
text = "Sattler;Cilli;Stumm;Zillertal/Tirol"
PARSE VAR text famName ";" firstName ";" city
SAY pp(famName)
SAY pp(firstName)
SAY pp(city)
EXIT
PP : RETURN "[" || ARG(1) || "]" -- "pretty print" ;)
Output:
PARSE 8
a and Use It for Parsing the Remaindertext = ";Sattler;Cilli;Stumm;Zillertal/Tirol"
PARSE VAR text 1 a +1 famName (a) firstName (a) city (a) .
SAY pp(famName)
SAY pp(firstName)
SAY pp(city)
EXIT
PP : RETURN "[" || ARG(1) || "]" -- "pretty print" ;)
Output:
PARSE 9
Makes it possible to immediately parse the result of an expression
Example:
Output (assuming date() returned the string "20 May 2059"):
year: 2059 month: May day: 20PARSE 10
PARSE PULL statements allow parsing a string read from the keyboard and assigning (parts of it) to Rexx variables in one step
Output:
PARSE 11
PARSE ARG allows to fetch argument values
Output:
WU
Prof. Mag. Dr. Rony G. Flatscher
Welthandelsplatz 1
1020 Wien/Vienna
Austria/Europe
www: www.wu.ac.at