Iteration

Definition

Iterative loops in LISP are the same as any other loop. They have a start, a conditional, and will repeatedly execute the body until the conditional is met such such that the loop terminates.

Common LISP Code

(setq a 6)
(loop
   (setq a (+ a 4))
   (when (> a 5) (return a))
  )

Common LISP Output

6;
10

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("(setq a 6)");
            lisp.add("(loop(setq a (+ a 4))(when (> a 5) (return a)))");
            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:
(setq a 6) = 6
(loop(setq a (+ a 4))(when (> a 5) (return a))) = 10
BUILD SUCCESSFUL (total time: 0 seconds)

Result

Awesome!