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 sequencesif equal(month, "JUly") or equal(month, "JULY") thenprintf(1, "month is: %s \n", {month})end if--loop to check ageif equal(age, 30) or equal(month, 40) thenprintf(1, "month is: %s", {month})elseputs(1,"age not matched")end if
Explanation
- Lines 1 and 2: We define two variables
ageandmonthin the atom data type. - Lines 5–7: The
ifstatement uses theequal()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
elseblock if theequal()method finds no equality between the atoms being compared.