OS/2 Procedures Language 2/REXX


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Value


The value of a variable can change, but the name cannot.  When you name a 
variable (give it a value), it is an assignment.  For example, any 
statement of the form, 

symbol = expression

is an assignment statement.  You are telling the interpreter to compute 
what the expression is and put the result into a variable called a symbol. 
 It is the same as saying, "Let symbol be made equal to the result of 
expression" or every time symbol appears in the text of a SAY string 
unprotected by single or double quotation marks, display expression in its 
place.  The relationship between a variable and a value is like that 
between a post-office box and its contents; The box number does not 
change, but the contents of the box may be changed at any time.  Another 
example of an assignment is: 

num1 = 10

The num1 assignment has the same meaning as the word symbol in the 
previous example, and the value 10 has the same meaning as the word 
expression. 
One way to give the variable num1 a new value is by adding to the old 
value in the assignment: 

num1 = num1 + 3

The value of num1 has now been changed from 10 to 13. 
A special concept in REXX is that any variable that is not assigned a 
value assumes the uppercase version of the variable as its initial value. 
 For example, if you write in a procedure, 

list = 2 20 40
SAY list

you see this on your screen: 

2 20 40

As you can see, list receives the values it is assigned.  But if you do 
not assign any value to list and only write, 

SAY list

you see this on your screen: 

LIST

Here is a simple procedure called VARIABLE.CMD that assigns values to 
variables: 

/* Assigning a value to a variable */
a = 'abc'
SAY a
b = 'def'
SAY a b
EXIT

When you run the VARIABLE procedure, it looks like this on your screen: 

[C:\]VARIABLE
abc
abc def

[C:\]

Assigning values is easy, but you have to make sure a variable is not used 
unintentionally, as in this example named MEETING.CMD: 

/* Unintentional interpretation of a variable */
the='no'
SAY Here is the person I want to meet
EXIT

When the procedure is run, it looks like this: 

[C:\]MEETING
HERE IS no PERSON I WANT TO MEET

[C:\]

To avoid unintentionally substituting a variable for the word, put the 
sentence in quotation marks as shown in this example of MEETING.CMD, which 
assigns a variable correctly: 

/* Correct interpretation of a variable the*/
the= 'no'
SAY "Here is the person I want to meet"
EXIT
  

Inf-HTML End Run - Successful