What is remove_item() method in Euphoria?

Overview

The remove_item() method is used to take an element out of a sequence. We specify the element we want to take out of the sequence. This specified item will have its first occurrence in the sequence removed.

Syntax

remove_item(take_out, take_out_from)

Parameter

  • take_out: The item we wish to remove from the sequence. It can be an atom or another sequence in the case of a nested sequence.

  • take_out_from : The sequence from which an item will be removed.

Return value

This method returns a sequence with a length of one item less than the length of the sequence take_out_from.

Code

Let’s look at the code below:

Note: To use this method, we must include the sequence.e file from the standard library in our program code.

include std/sequence.e
--declare variables
sequence outcome1, outcome2, take_out_from1, take_out_from2
--assign values
take_out_from1 = {10,20,30}
take_out_from2 ={"Euphhoria", {1,2,3,4}}
-- using the remove_item method
outcome1 = remove_item(30,take_out_from1)
outcome2 = remove_item("Euphhoria",take_out_from2)
--displaying the results
puts(1,"Removes 30 from {10,20,30} gets : ")
print(1,outcome1)
puts(1,"\nRemoves \"Euphhoria\" from {\"Euphhoria\", {1,2,3,4}} gets : ")
print(1,outcome2)
puts(1,"\nRemoves the first occurence of \"2\" from {3,2,4,5,2} gets : ")
print(1,remove_item(2,{3,2,4,5,2} ))

Explanation

  • Line 1: We include a library package.

  • Line 4: We declare variables.

  • Lines 7 to 8: We assign values to declared variables.

  • Lines 11 and 12: We use the remove_item() method.

  • Lines 15 to 20: We print some value to the output.

Free Resources