Skip to content

Instantly share code, notes, and snippets.

@francois
Created December 14, 2008 01:53
Show Gist options
  • Save francois/35596 to your computer and use it in GitHub Desktop.
Save francois/35596 to your computer and use it in GitHub Desktop.
(defn process [socket]
(let [ in (java.io.PushbackReader. (make-reader (. socket getInputStream)))
out (java.io.PrintWriter. (make-writer (. socket getOutputStream)))]
(loop [stack ()]
(let [form (read in)]
(println "STACK:\t" stack)
(println "READ:\t" form)
(cond
(number? form) (recur (conj stack form))
(= 'quit form) (do
(. out println "Connection closed by client, closing socket")
(. out flush)
(. socket close))
:else (do
(. out println "Syntax error: unrecognized form" form)
(. out flush)
(. socket close)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment