What is a variable in Euphoria?

Introduction

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:

  • First, we create a memory location to hold these values.
  • Then, we indicate a name and the type of value it will hold.
  • Lastly, the value is added to the memory location we create.

What is a variable?

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.

Variables in Euphoria

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.

Identifiers

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:

  • Identifiers must start only with the letter A-Z or a-z with more letters, digits, and underscores coming after.
  • Every other character, apart from the ones listed above, cannot be in the identifier.
  • Euphoria identifiers are case-sensitive. Hence, it is good practice to maintain a single case throughout a code for your identifiers. The lowercase is preferred.

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.

Declaring a variable

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.

Assigning values to a variable

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.

Free Resources