What is the is_in_list() method in Euphoria?

Overview

The is_in_list() method in Euphoria lets you determine the availability of an object in a list. Hence, this method can be used in loops and other conditionals statements.

The is_in_list() is an inbuilt function in Euphoria and is part of the search.e standard library. In order to use this method, we have to add include std/search.e at the top of our code.

Syntax

is_in_list(search_item, items_list)

Parameters

  • search_item: This is the object that we are checking to see if it is present in the items_list.
  • items_list: This is the list that may have the search_item in it.

Return value

The is_in_list() method returns 1 if search_item is in the items_list. Otherwise, it returns 0.

Code

The code below demonstrates how we can use the is_in_list() function.

include std/search.e
sequence user_age, name, cars
name = "spring"
user_age = {3,4}
cars = "offroads"
if is_in_list(user_age, {100, 45, 2, 75, 121}) then
print(1,user_age)
else
puts(1,"not in the list")
end if
printf(1,"\n%d",is_in_list(name,"SPRINGBOARD"))
printf(1,"\n%d",is_in_list(cars,{"saloons","trucks","offroads"}))

Explanation

In the code sample above, we use the is_in_list method as a condition of the if statement.

  • Line 2: We include the search.e file into our program code.

  • Line 4: We declare some variables as sequence data type.

  • Lines 5 and 7: We assign values to the variables.

  • Line 9: We provide an if statement, with is_in_list() as one of its conditions to check if user_age is in the provided age list.

  • Line 10: We print some of the values returned from the condition on line 9.

  • Lines 11-13: We provide the else block of the if statement and print some of the values returned.

  • Line 15-16: We print the value returned from the is_in_list() function as an output.

Free Resources