eq, equal

eq, equal — compare for identity and equivalence.

Syntax

eq (s_exp, s_exp)
equal (s_exp, s_exp)

		

Arguments

s_exp

Any Gamma or Lisp expression.

Returns

eq returns t if the two arguments are exactly the same Gamma or Lisp element, otherwise nil. equal returns t if the two arguments "look" the same but are not necessarily pointers to the same memory.

Description

The interpreter's storage mechanism allows a particular element to be referenced from more than one location. Functions like cons and list do not copy their arguments, but simply construct a higher level entity (in these cases a list) which refers to their arguments. The copy function will create a new top-level structure but maintain references to the sub-elements of the original list. The eq function tests to see whether two elements are in fact references to the same element. The equal function determines whether two elements have identical contents, but are not necessarily references to the same element. All things which are eq are also equal. Things which are equal are not necessarily eq.

The equal function will travel lists, arrays and instances to compare sub-elements one at a time. The two elements will be equal if all of their sub-elements are equal. Numbers are compared based on actual value, so that equal(3, 3.0) is t. Strings are compared using strcmp.

Symbols are always unique. A symbol is always eq to itself.

Example

Gamma> a = #acme;
acme
Gamma> b = #acme;
acme
Gamma> equal(a,b);
t
Gamma> eq(a,b);
t

Gamma> a = "acme";
"acme"
Gamma> b = "acme";
"acme"
Gamma> equal(a,b);
t
Gamma> eq(a,b);
nil

Gamma> equal(5,5);
t
Gamma> eq(5,5);
nil

Gamma> x = list(#acme, list(1,2,3), "hi");
(acme (1 2 3) "hi")
Gamma> y = copy (x);
(acme (1 2 3) "hi")
Gamma> equal(x,y);
t
Gamma> eq(x,y);
nil
Gamma> equal(cadr(x),cadr(y));
t
Gamma> eq(cadr(x),cadr(y));
t
Gamma> 
		

See Also

Comparison Operators