Printing

Definition

Printing to the screen is a critical element - and LISP handles this via the format keyword. The following example consists of three primary parts. First there is the call to format itself which immediately wants a parameter (function) of either t, nil, or stream. These are quickly defined as follows:

t - send output to terminal
nil - return as a string
stream - file/some other program/etc
Following the format function is the string that contains the text along with some optional markers. There are a large number of optional marker directives, but a common one to examine is ~% which represents a breakline.

Unforunately Jatha failed this particular test.

Common LISP Code

(format t "My lucky number: ~D~%I prefer ~D wheels ~%Phones have ~D keys~%" 7 (list 2) 9)

Common LISP Output

My lucky number: 7
I prefer 2 wheels
Phones have 9 keys

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("(format t "My lucky number: ~D~%I prefer ~D wheels ~%Phones have ~D keys~%" 7 (list 2) 9)");

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

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

    }
}

Java Output (Jatha)

compile:
run:
ERROR: org.jatha.compile.UndefinedFunctionException: The function "FORMAT" is undefined.
ERROR: org.jatha.compile.UndefinedFunctionException: The function "FORMAT" is undefined.
(format t "My lucky number: ~D~%I prefer ~D wheels ~%Phones have ~D keys~%" 7 (list 2) 9)") = "org.jatha.compile.UndefinedFunctionException: The function "FORMAT" is undefined."
(format t "My lucky number: ~D~%I prefer ~D wheels ~%Phones have ~D keys~%" 7 (list 2) 9)") = "org.jatha.compile.UndefinedFunctionException: The function "FORMAT" is undefined."

Result

Tada!