Equality

Definition

LISP has 4 key forms of equality. First, if there is a sense of numerical equality, then the notation is to use =. If there is equality of two symbols, such that they are identical then the notation is eq. Got it? Good...because it gets completely wack... If there are two symbols, and they are copies of some other list, then they are not eq, rather they are (3rd notation here) equal. Then there is the alias equality. The notation of eql is same as eq and =. The notation of equal is same as eql, but when used against cons (lists) - it evalutes to true if and only if the respective cars and cdrs are equal. Gah.

Unfortunately it would appear that the equal function is unsupported while eql and = are functional in Jatha. Check it out in action on Jatha...

Common LISP Code

(eq 'c 'c)
(eq 'd 'c)
(= 2 4)
(eq '(d e f) '(d e f))
(equal '(z x a) '(z x a))
(eql 'b 'b)
(eql 4 4)

Common LISP Output

T
NIL
NIL
NIL
T
T
T

Java Code

package jathaverify;
import org.jatha.*;
import org.jatha.dynatype.*;
import java.util.*;
public class Main  {

    public Main() {
    }

    public static void main(String[] args) {
        Jatha myLisp  = new Jatha(false, false);
        myLisp.init();
        myLisp.start();

        try {
            List lisp = new ArrayList();

            lisp.add("(eq 'c 'c)");
            lisp.add("(eq 'd 'c)");
            lisp.add("(= 2 4)");
            lisp.add("(eq '(d e f) '(d e f))");
            lisp.add("(equal '(z x a) '(z x a))");
            lisp.add("(eql 'b 'b)");
            lisp.add("(eql 4 4)");

            Iterator i = lisp.iterator();
            while (i.hasNext()) {
                String query = i.next().toString();
                System.out.println(query + " = " + myLisp.eval(query));
             }

        } catch (Exception e) {
            System.err.println("LISP Exception: " + e);
        }

    }
}

Java Output (Jatha)

compile:
run:
(eq 'c 'c) = T
(eq 'd 'c) = NIL
(= 2 4) = NIL
(eq '(d e f) '(d e f)) = NIL
ERROR: org.jatha.compile.UndefinedFunctionException: The function "EQUAL" is undefined.
(equal '(z x a) '(z x a)) = "org.jatha.compile.UndefinedFunctionException: The function "EQUAL" is undefined."
(eql 'b 'b) = T
(eql 4 4) = T
BUILD SUCCESSFUL (total time: 0 seconds)

Result

Cool!