RefEquals

From MiniScript Wiki
Revision as of 08:13, 17 November 2023 by Marc Gurevitx (talk | contribs) (→‎Example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The refEquals function checks two values for reference equality. This is different from the == operator, which checks whether two values are equivalent (e.g., two maps that contain equal key/value pairs, or two lists which contain equal values).

Whenever refEquals(a, b) is true (1), then you know that any modification of a will also be seen via b, because a and b refer to the same object.

For immutable types – nulls, numbers and string's – refEquals returns the same result as the == operator.

Arguments

Parameter Name Default Value Meaning
a any value first argument
b any value second argument


Example

a = {"foo":42}
b = a
c = {"foo":42}
print a == b          // prints 1, because a and b have the same value
print a == c          // prints 1, because a and c have the same value
print refEquals(a,b)  // prints 1, as these are the same map
print refEquals(a,c)  // prints 0, as these are different maps

print refEquals(42,42)// prints 1
nan = 0/0
print refEquals(nan,nan)//prints 0