Programming involves numerous manipulations of values. There is usually a provision for storing these values in the computer memory in any programing language. This way, they can be used when needed. This process of storage involves:
In the explanation above, we see the word “memory location” used a lot. In very simple terms, a variable is a memory location reserved by the computer to contain some piece of data. When we create a variable, we tell the computer to reserve a location in the memory where data will be stored either immediately or later. This location/space is named so that it can be properly be referred to throughout the code. These names are called identifiers.
After indicating the variable type in the variable declaration, the Euphoria interpreter decides what legal value a variable can hold. We shall discuss variables in Euphoria under the following headings.
We mentioned earlier how identifiers are names given to a variable. In Euphoria, the following rules should be observed while choosing an identifier for your variable:
Some legal identifiers in Euphoria:
t
price32
BallPoint
boiling_point
can_have_very_long_ones
Reserved words cannot be used as identifiers. Some Reserved words in Euphoria include: and
, exit
, override
, as
, export
, procedure
, do
, else
, to
if
, loop
, without
, and so on.
Variables in Euphoria are explicitly declared. This shows the type of value it can hold before any value is assigned to it. For example:
integer name1, name2, name3
sequence age, time
name1
, name2
, and name3
are three different variables all declared as the integer type. age
and time
are of the sequence type.
Declaration is not the same as value assignment. You can’t attempt to read from the variable before assigning a value to avoid any error messages from the interpreter.
Values are assigned to variables in Euphoria using the assignment operator (=
).
This value has to be of the type indicated in the declaration to avoid errors.
For example:
--declare it first
sequence a_sequence
--then assign values
a_sequence = {1,3,5, "juan"}
Note that
--declare it first
and--then assign values
are comments.
In short, working with variables in Euphoria is quite easy as the data types available in the language are just a couple. This surely isn’t a handful when it comes to declaration.