Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
communitycreator

How to use the tail function in Euphoria

NDUKWE CHIDERA K.

Overview

In Euphoria, the tail() function is used to return members of a sequence beginning from the end of the sequence, with the length of the member returned, depending on the number indicated.

Syntax

tail(any_sequence,tail_size)

Parameters

  • any_sequence: This is the sequence we wish to get the tail value. It can be of any sequence type.
  • tail_size: With this parameter, we can indicate the size of the returned tail value. It can be zero. If it is more than the size of the sequence, the whole sequence will be returned. This parameter is of type integer.

The working dynamics of this method

First, the parser checks the function for the indicated sequence and size it will return from the rightmost part including whitespaces. So, the return value is going to be a sequence containing the tail value.

How to use this method

  • We call the function in our program. We don’t need to include any file, because it is a part of the core standard library.
  • Next, we provide the sequence whose tail is to be returned and the size of the tail value we wish to return. And that is it you can use the return value any way we want to.

Example

The code below shows how the tail of certain sequences is saved as a value of the variables seq1, seq2, and seq3.


sequence seq1, seq2, seq3
seq1 = tail({1,3,5,7}, 0)
seq2 = tail("John Doe", 4)
seq3 = tail("Marathon", 20)
print(1,seq1)
printf(1," \n %s \n %s ",{seq2,seq3})

Explanation

  • Line 2: We declare the sequence variables seq1, seq2, and seq3.
  • Line 3–5: We use the sequences to hold the tail value of certain sequences returned by the tail() function.
  • Line 6 and 7: We use the print and printf methods to print the output.

From the output, we can see how seq1 returns as an empty sequence, because the tail_size parameter supplied is 0.

RELATED TAGS

euphoria
communitycreator
RELATED COURSES

View all Courses

Keep Exploring