From: Mark McConnell
Subject: Flow of control in Jil
Date: 
Message-ID: <d3aed052.0408110925.199f8d35@posting.google.com>
I have been playing with Jil, Franz's Lisp-like language which
compiles to Java class files.  I'm having trouble with iteration. 
Here is my test code.

(def-java-class Mark ()
  :public
  ())

(def-java-method main ((args (array String))) void
  :public :static
  (System.out.println (s+ "Arg 0 is " (aref args 0)))
  (do ((i 1 (+ i 1))
       (sum 0 (+ i sum)))
      ((> i 10)
       (System.out.println (s+ "Sum of [1..10] = " sum ".")))))

If you leave out the do form, it works (it produces a Java class file
that prints arg 0).  But the do form won't compile, and gives this
message.
Error: Illegal form for function call
       ((javatools.jil.source::i 1 (+ javatools.jil.source::i 1))
        (javatools.jil.source::sum 0
         (+ javatools.jil.source::i javatools.jil.source::sum)))
It's treating (i 1 (+ i 1)) as a function call.  Thus it isn't parsing
do's special syntax.  And in fact, the Jil documentation says do is
not a special form in Jil, so (d'oh) there is no reason it *should* be
parsed specially.  The question is what to replace it with.

Further notes, in descending order of interest...

The Jil documentation says that the following are the special forms in
Jil.  (I'll omit some that have nothing to do with control flow.)
progn
block
let
setq (including setf functionality in some cases)
ref (digs into slots of slots of...)
if, and, or
handler-case, unwind-protect, throw
There is also a macro facility (yay!)
I'm trying to think how to write my own 'do' macro using these tools. 
But without things like go and tagbody, I don't know how.

The sample Jil code that comes with ACL 6.2 uses dotimes, but not do,
prog, or loop.

I wrote the Jil equivalent of
(defun sum (n result)
  (if (= n 0) result (sum (1- n) (+ n result))))
It compiled to satisfactory, straightforward Java bytecode.  But like
Java in general, it's not properly tail-recursive, so you can't use it
for large n.  Some kind of 'do' is necessary.

Various modifications of 'do' also failed in Jil (pulling the bindings
into an outer let; rewriting it with prog).