What is the equal() method in Euphoria?

Overview

In Euphoria, equal() is a built-in routine of the standard library, which is used to draw an equality comparison between two variables, and return either 0 or 1 depending on the outcome of the comparison.

Syntax

equal(left_val,right_val)

Parameters

This method takes two parameters left_val and right_val. These represent the values for which we’re checking equality. They can be of atom, sequence, or object data type.

Return Value

The function returns the value 1 if both right_val and left_val are equal. Otherwise it returns 0.

sequence month ="JULY"
atom age = 20
--look to check equality of two sequences
if equal(month, "JUly") or equal(month, "JULY") then
printf(1, "month is: %s \n", {month})
end if
--loop to check age
if equal(age, 30) or equal(month, 40) then
printf(1, "month is: %s", {month})
else
puts(1,"age not matched")
end if

Explanation

  • Lines 1 and 2: We define two variables age and month in the atom data type.
  • Lines 5–7: The if statement uses the equal() method to check for equality of the defined sequence in its condition.
  • Lines 10–14: We repeat the same function as we did in lines 5–7. However, we execute an else block if the equal() method finds no equality between the atoms being compared.

Free Resources