Skip to content

Instantly share code, notes, and snippets.

@gfredericks gfredericks/ns.clj
Created Aug 4, 2010

Embed
What would you like to do?
;; Both of these are inputs at runtime, separately
(def lib "(ns my-ns) (defn x [n] (+ n 5))")
(def code '(x 12))
(eval code) ;; doesn't work of course
;; I want to be able to do this without "using" the namespace
@danielfm

This comment has been minimized.

Copy link

commented Aug 4, 2010

A eval-in-ns function could be something like this, I think:

(defn eval-in-ns [form ns]
  (use ns)
  (eval form))

;; Usage:
(eval-in-ns '(func 10) 'my-ns)

That (use ..) is mandatory since you don't want to do that in every namespace you use eval-in-ns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.