[plt-scheme] Android; compiling to Java byte code; Clojure
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]
(cond
((nil? stream)
nil)
((eql? (first stream) \c)
[:more (rest stream)])))
:more (fn [stream]
(cond
((nil? stream)
nil)
((eql? (first stream) \a)
[:more (rest stream)])
((eql? (first stream) \d)
[:more (rest stream)])
((eql? (first stream) \r)
[:end (rest stream)])))
:end (fn [stream]
(cond
((nil? stream)
:t)))}]
(fn [stream]
(loop [state :init
stream stream]
(let [ret ((state states) stream)]
(and ret
(if (eql? ret :t)
:t
(recur (ret 0) (ret 1)))))))))
Of course, at this point you're just emulating TCO.
Henk Boom