# equal

Definition: | integer i = equal(object a, b)
Description: | Compare two objects to see if they are the same. Return true (1) if they are the same, or false (0) if they are different.
pwa/p2js: | Supported.
Comments: | Note that Euphoria typically needs equal() or compare() on each and every non-trivial conditional test, whereas Phix can just use the more natural infix operators =, !=, etc directly. In reality Phix only supports equal() for legacy code and compatibility with Euphoria. You can also use sq_eq() to obtain element-wise results, compatible with a=b under Euphoria.
Example 1: |
    if equal(PI, 3.14) then
    --if PI=3.14 then -- (equivalent, but not Euphoria compatible)
        puts(1, "give me a better value for PI!\n")
    end if
Example 2: |
    if equal(name, "George") or equal(name, "GEORGE") then
    --if name="George" or name="GEORGE" then -- (equivalent, "")
        puts(1, "name is George\n")
    end if
Example 3: |
    sequence res = sq_eq({1,1,4,4},{1,2,3,4}) -- res := {1,0,0,1}, aka {true,false,false,true}
Implementation: | Implemented via %opJcc, %opJccE, and %opScmp in builtins\VM\pJcc.e (an autoinclude) - be warned however it is low-level complicated stuff that you do not need to know. sq_eq() is implemented in builtins\psqop.e
See Also: | compare, equals operator (=)
Technicalia | Technically equal(a,b) is equivalent to the expression compare(a,b)=0, not that you really needed to know that. Be advised that sq_eq() yields a character-wise comparison on (nested) strings, and throws an exception if their lengths are not the same.