These files allow you to review the topics covered in the Introductory Rexx Tutorial presented at the SHARE Technology Conference 2-7 March 1997.

These files are a supplement to the discussion in that session and are intended as a refresher for the topics covered there. The refresher course is automated as a series of Rexx programs, which are generally portable to any platform.

These sample programs use basic elements of the Rexx language and most of them require no modification to run in any operating system environment. The exceptions are those programs that interact with the operating system. To use these programs in your home environment, please review the notes that follow:

If you are running under OS/2, no changes are required.

For all other platforms, you will need to make the following changes:

The file names are suitable for an OS/2, DOS, or Windows environment. When copying the files to another platform, be sure to choose appropriate names for Rexx programs on that platform.

The files addr1.cmd, addr2.cmd, and addr3.cmd include a command to produce a directory listing under OS/2 or DOS ("dir" or "dir /w"). You must change this to a command that is valid for your operating system. Any valid operating system command will illustrate the points being made in these programs.

The files are identified below.

FIRST.CMD

simplest Rexx program - how to do output

NEXT.CMD

simple but better Rexx program - output again

PROMPT1.CMD

getting fancier - how to get input and

PROMPT2.CMD

variations on input and output

PROMPT3.CMD

GREET1.CMD

simplest loop

GREET2.CMD

more useful looping

NUMBERS.CMD

how numbers are treated in Rexx

DATATYPE.CMD

determining what kind of string this is - validating input

DATATYP2.CMD

CONTINUE.CMD

continuation of lines in a program

CONTINU2.CMD

PRECISE.CMD

Rexx's decimal arithmetic

FUNCS.CMD

using functions - and some useful functions

ADDR1.CMD

interfacing with the external environment, also

ADDR2.CMD

illustrating some potential pitfalls in Rexx and

ADDR3.CMD

how to avoid them

MAGICNO.CMD

a self-documenting Rexx program, though all good programmers document their code

/* DATATYPE.CMD */
/* Even though everything is a string in REXX, it is sometimes useful to know what sort of string we have
- particularly if we want to attempt to validate user response to a prompt */
say ''
say 'Introducing "DATATYPE()"'
say ''
say 'Type a number or a letter'
say ''
pull reply
say ''
if datatype(reply) = 'NUM' then say 'You entered a number'
else say 'You entered a letter'

DATATYP2.CMD

/* DATATYP2.CMD */
/* Even though everything is a string in REXX, it is sometimes useful to know what sort of string we have
- particularly if we want to attempt to validate user response to a prompt */
say ''
say 'Introducing "DATATYPE()"'
say ''
say 'Type a number'
say ''
pull reply
say ''
if \datatype(reply, 'w') then say 'That was not a whole number'
else say 'That was a whole number'

CONTINUE.CMD

/* CONTINUE.CMD */
/* Continuation is REXX is easy. Suppose we want to create a really long string but we want to see everything
in our editor without having to do left/right scrolling */
string = 'January February March April May June July August',
'September October November December'
say ''
say string

/* ADDR1.CMD */
/* REXX interacts well and easily with its environment. If an expression does not evaluate to a valid REXX
clause, the result is automatically send to the external environment to be handled */
dir

ADDR2.CMD

/* ADDR2.CMD */
/* REXX interacts well and easily with its environment. If an expression does not evaluate to a valid REXX
clause, the result is automatically send to the external environment to be handled. But some care is in
order. If uninitialized, "dir" evaluates to "DIR". This is not a REXX clause so is sent to the OS to handle.
What if, somewhere else in your program, you tried to use "dir" as a variable name? */
say ''
dir = 'C:\RXTUTOR\SHARE\INTRO2'
say ''
say 'Some code gets executed here, and then .....'
say ''
dir

ADDR3.CMD

/* ADDR3.CMD */
/* REXX interacts well and easily with its environment. If an expression does not evaluate to a valid REXX
clause, the result is automatically send to the external environment to be handled. But some care is in
order. If uninitialized, "dir" evaluates to "DIR". This is not a REXX clause so is sent to the OS to handle.
What if, somewhere else in your program, you tried to use "dir" as a variable name? So it's always safe ...
and generally considered good programming practice to enclose commands for the external environment in quotes.
This ensures they are literal strings and not evaluated by REXX before execution. It also allows for the use of
characters that would be considered by REXX to be an operator. */
say ''
dir = 'C:\RXTUTOR\SHARE\INTRO2'
say ''
say 'Some code gets executed here, and then .....'
say ''
'dir /w'

MAGICNO.CMD

/* MAGICNO.CMD */
/* Self-documenting program */
secret_number = random(1, 10)
guessed_it = 0
say 'I''m thinking of a number between 1 and 10'
say 'Let''s see if you can guess it'
do until guessed_it
say ''
say 'Pick a number or type "Q" if you give up'
pull guess
if guess = 'Q' then leave
if guess = secret_number then guessed_it = 1
else say 'Sorry, that''s not it'
end
say ''
if guessed_it then say 'Hey, that''s right! The number I was thinking of was' secret_number
say 'Thanks for playing my game'