Difference between revisions of "RefEquals"

From MiniScript Wiki
Jump to navigation Jump to search
(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...")
 
m (On immutable types)
Line 2: Line 2:
  
 
Whenever <c>refEquals(a, b)</c> is true (1), then you know that any modification of <c>a</c> will also be seen via <c>b</c>, because <c>a</c> and <c>b</c> refer to the same object.
 
Whenever <c>refEquals(a, b)</c> is true (1), then you know that any modification of <c>a</c> will also be seen via <c>b</c>, because <c>a</c> and <c>b</c> refer to the same object.
 +
 +
For immutable types – <c>null</c>s, <c>number</c>s and <c>string</c>'s – <c>refEquals</c> returns the same result as the <c>==</c> operator.
  
 
=== Arguments ===
 
=== Arguments ===

Revision as of 20:10, 11 November 2023

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