eq, equal
eq, equal — compare for identity and equivalence.
eq (s_exp, s_exp)
equal (s_exp, s_exp)
s_expAny Gamma or Lisp expression.
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.
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.
Gamma>a = #acme;acmeGamma>b = #acme;acmeGamma>equal(a,b);tGamma>eq(a,b);tGamma>a = "acme";"acme"Gamma>b = "acme";"acme"Gamma>equal(a,b);tGamma>eq(a,b);nilGamma>equal(5,5);tGamma>eq(5,5);nilGamma>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);tGamma>eq(x,y);nilGamma>equal(cadr(x),cadr(y));tGamma>eq(cadr(x),cadr(y));tGamma>