What are the data types in Euphoria?

Share

Introduction

Euphoria is a simple and concise programming language. It is well-known for its syntax. This is very obvious in how simplified the data types available in the language have been made. There are two data types in Euphoria. We take a look at them in this shot.

Data types in Euphoria

There are two main data types in Euphoria:

  1. Atom
  2. Sequence

1. The Atom data type

An atom is a number that can either be a 31-bit integer or a 64-bit floating-point. Atoms can be between approximately -1e300 and +1e300 with 15 decimal digits of accuracy.

In the example below, variables a, b, c, d and e are all declared an atom and assigned legal values:

atom a, b, c, d, e --declaration
a  = 'C' 
b  = 0
c  = 5894
d  = 40.6
e  = -1e9

2. The Sequence data type

A sequence is a set of numeric and text values which can be accessed through their index. Every data object in Euphoria can either be an atom or a sequence.

Sequences have indexes that begin with 1 as the first index. This is unlike other programming languages with an array index that starts from 0. We can declare and define a sequence in Euphoria as follows:

sequence age, scores, names, empty

age = {2, 10, 60, 20, 13, 40}
scores = {1,{20, 30},4, {5,60{6}}}
names = {{"Dan","Jane"}, 97.25}     
empty = {} -- the 0 element sequence

Inside the curly brackets, we write down the values of the sequence.

Other data types also exist in Euphoria.

The Integer data type

This is a type of the Atom data type. It is either a positive or a negative whole number between -1073741824 and +1073741823.

For example:

interger int1, int2
int1 = 40909397
int2 = 1

The Object data type

This is what we might call a super data type. This is because it can contain both sequences, atoms, and integers. Objects in Euphoria are declared and defined in the following way:

atom var1
object obj1, obj2, obj3
var1 = 3 
obj1 = {2, 12, var1}
obj2 = 100
obj3 = 'E' 

An atom is declared and assigned a value in the example above. It is added as a part of the values assigned to the object. This shows how the Object data type accepts any data type.

Code

#! A simple print statement to print a sequence
include std/io.e
--declare the variable
atom age
sequence detail
/* assign values */
age = 18
detail ={{"Dan","Jane"}, 97.25}
print(1, age)
puts(1,"\n")
puts(1, detail[1][2] )

Explanation

The code example above declares an atom and a sequence data type. T hese types were output to display using the print() and puts() function on line 9 and line 11, respectively.