What is the length() function in Euphoria?
Overview
The length() function in Euphoria is used to return the size of a sequence.
The sequence length depends on how many members the sequence has and the number of whitespaces it includes.
Syntax
length(my_seq)
my_seq: This is the sequence variable whose size needs to be determined.
Return value
This function returns an atom, which is the length of the sequence.
Code example
The code written below returns the size of the sequence.
--declare atom variablesatom an_atom1, an_atom2, an_atom3--check the length of different variablesan_atom1 = length({0,1,2,3,4,5,6,7,8,9})an_atom2 = length({{1,2}, {3,4}, {5,6}})an_atom3 = length("I am going to win it")--print the result to outputprint(1,an_atom1)puts(1,"\n")print(1,an_atom2)puts(1,"\n")print(1,an_atom3)
Code explanation
- Line 2: We declare the atom variables.
- Lines 5–7: We call the
length()method on the sequence and hold the return value in the assigned value. - Lines 10, 13, and 16: We print the output values to the screen, using the
printf()method. - In this code, the
puts()methods is used to print new lines.