Last active
February 23, 2022 21:41
-
-
Save eerohele/45a255b249a2154431bfd70502cb625a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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