A sequence is a very important data type in Euphoria. The variables of the sequence data type have their values enclosed inside curly braces {}
or inside double quotation marks ""
.
We can perform operations on elements of a sequence. These elements are indexed. However, the index starts from 1
instead of zero.
prepend()
functionThe prepend()
function is used to add elements at the beginning of a sequence.
This function includes the specified value at the start of a sequence. This means that this new element now takes the index 1
.
prepend(sequence,newitem)
sequence
, is the sequence to which we’re going to add an item. It can be any sequence of length >= 0
.newitem
, is the new element that we’re going to add to the sequence. This can be an atom
or even another sequence
.This function returns a sequence with a length greater than the original sequence.
--declare some sequence variablessequence prependedTo, toBeAddedTo--define an atom variableatom scores = 5toBeAddedTo = {6,7,8}prependedTo = prepend(toBeAddedTo,scores)print(1,prependedTo)
Line 3: We declare two sequence variables, toBeAddedTo
and prependedTo
. The toBeAddedTo
variable has the sequence to which we want to add add an item. prependedTo
has the return value of the prepend()
function.
Line 6: We define an atom scores
. This is later on prepended to the sequence.
Line 10: We call the prepend()
function and save its return value in the variable prependedTo
.
Line 12: We print the return value of the variable prependedTo
.