Skip to content

Instantly share code, notes, and snippets.

@mjg123
Last active December 10, 2015 23:21
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 mjg123/a1dca856cd08682f5676 to your computer and use it in GitHub Desktop.
Save mjg123/a1dca856cd08682f5676 to your computer and use it in GitHub Desktop.
(when (not (find-ns 'mattermost))
(.setDynamic ;; <- This horrific interop into Var.java to counter
(intern (create-ns 'mattermost) ;; CLJ-951, which is a closed/wishlist bug reporting that
(with-meta '*me* {:dynamic true}) ;; <- this is actually not propagated fully (is, in fact, useless) :(
"foo")))
(defn eval-w-bindings [str user]
(binding [*ns* (create-ns 'mattermost)
mattermost/*me* user]
(clojure.core/refer 'clojure.core)
(-> str read-string eval)))
(eval-w-bindings "(str \"hello \" *me*)" "andrew")
;; => "hello andrew"
@mjg123
Copy link
Author

mjg123 commented Dec 10, 2015

This is what I wanted:

user=> (eval-w-bindings "(defn x [] *me*)" "someone")
#'mattermost/x
user=> (eval-w-bindings "(x)" "mjg")
"mjg"
user=> (eval-w-bindings "(x)" "jones")
"jones"

And the above code has does it! Yay! But I'd also like to be able to pass in the namespace instead of hard-coding mattermost everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment