Skip to content

Instantly share code, notes, and snippets.

@eerohele
Last active February 23, 2022 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eerohele/45a255b249a2154431bfd70502cb625a to your computer and use it in GitHub Desktop.
Save eerohele/45a255b249a2154431bfd70502cb625a to your computer and use it in GitHub Desktop.
(def eval-context (atom {}))
(defn handle
"Imaginary message handler that sets the namespace received out of band."
[ns]
(swap! eval-context assoc #'*ns* (find-ns ns)))
(defn repl
[]
(loop []
,,,
;; `in` is a LineNumberingPushbackReader wrapping a socket
;; Block until there's something to read, then read maybe one character.
(let [n (.read in)
;; Now that we're no longer blocked, set the ns to the ns we received
;; out of band.
_ (set! *ns* (get @eval-context #'*ns* (the-ns 'user)))
;; Unread however many chars we read earlier
_ (.unread in n)
;; Proceed as usual.
[form s] (read+string ,,, in)
,,,]
(eval form)
,,,)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment