RefEquals

From MiniScript Wiki
Revision as of 22:54, 9 November 2023 by JoeStrout (talk | contribs) (Created page with "The <c>refEquals</c> function checks two values for reference equality. This is different from the <c>==</c> operator, which checks whether two values are ''equivalent'' (e.g...")
(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.

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