Conses

Definition

Before I actually verify a LISP list, it is probably important to get the terminology down. First, a LISP list is a singly-linked list. Each cell of this list is called a cons and is essentially made up of two pointers, called the car and cdr. In other words, a cons is just a two-field record with fields car and cdr. Here's some stuff you can do with cons, car, and cdr with respect to LISP; the same actions are cross checked in Jatha.

Common LISP Code

(cons 8 9)
(cons (cons 4 2) 1)
(cdr (cons 2 1))
(car (cons 6 1))

Common LISP Output

(8 . 9)
((4 . 2) . 1)
1
6

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("(cons 8 9)");
            lisp.add("(cons (cons 4 2) 1)");
            lisp.add("(cdr (cons 2 1))");
            lisp.add("(car (cons 6 1))");

            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:
(cons 8 9) = (8 . 9)
(cons (cons 4 2) 1) = ((4 . 2) . 1)
(cdr (cons 2 1)) = 1
(car (cons 6 1)) = 6
BUILD SUCCESSFUL (total time: 0 seconds)

Result

Whoohoo!