Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created August 4, 2010 00:03
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 gfredericks/507413 to your computer and use it in GitHub Desktop.
Save gfredericks/507413 to your computer and use it in GitHub Desktop.
;; 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
Copy link

danielfm 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