Numbers

Definition

A number is a string of digits with an optional + or - prefix designation. A real number is basically well, a number that can be specified with a decmial for whatever accuracy or precision one is looking for. A rational number is represented by a divisor / between two integers. The standard arithmetic functions are: +, -, *, /, floor, ceiling, mod, sin, cos, tan, sqrt, exp, and expt. All of them accept any kind of number as an argument. Arithmetic in LISP is a bit different as everything uses prefix notation rather than infix.Here's the sample verification.

Common LISP Code

(+ 3 9 2 3)
(- 3 2 4 2 3)
(* 12 49)
(+ 1 2 3 4 5 6 7 8 9)
(2/3)

Common LISP Output

17
588
45
0.3333333333333333

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("(+ 3 9 2 3)");
            lisp.add("(* 12 49)");
            lisp.add("(+ 1 2 3 4 5 6 7 8 9)");
            lisp.add("(/ 5 15)");

            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:
(+ 3 9 2 3) = 17
(* 12 49) = 588
(+ 1 2 3 4 5 6 7 8 9) = 45
(/ 5 15) = 0.3333333333333333
BUILD SUCCESSFUL (total time: 0 seconds)

Result

Yay!