[plt-scheme] Android; compiling to Java byte code; Clojure

From: Henk Boom (lunarc.lists at gmail.com)
Date: Sat Nov 24 21:09:43 EST 2007

On 22/11/2007, Shriram Krishnamurthi <sk at cs.brown.edu> wrote:
> But let me ask a question first.  Can you show us the central
> definition from this paper in Clojure?

I decided to give it a crack. I think the following should work,
though it won't compile and the error messages are most unhelpful.
(What is clojure.lang.Compiler$CompilerException: REPL:2: null
supposed to mean =S)

(def machine
  (let [states {:init (fn [stream]
                          ((nil? stream)
                          ((eql? (first stream) \c)
                           [:more (rest stream)])))
                :more (fn [stream]
                          ((nil? stream)
                          ((eql? (first stream) \a)
                           [:more (rest stream)])
                          ((eql? (first stream) \d)
                           [:more (rest stream)])
                          ((eql? (first stream) \r)
                           [:end (rest stream)])))
                :end (fn [stream]
                          ((nil? stream)
    (fn [stream]
      (loop [state :init
             stream stream]
        (let [ret ((state states) stream)]
          (and ret
            (if (eql? ret :t)
              (recur (ret 0) (ret 1)))))))))

Of course, at this point you're just emulating TCO.

    Henk Boom

Posted on the users mailing list.