Alan, Something like this might work for you -
(defmacro eval-in "Eval a Clojure form in a different namespace and switch back to current namespace. Args: code - Clojure form as string ns - Target namespace as string" [code ns] `(do (in-ns '~(symbol ns)) (let [ret# (eval '~(read-string code))] (in-ns '~(ns-name *ns*)) ret#))) Warning - I haven't really tested this code. -BG On Tue, Dec 18, 2012 at 12:37 PM, Alan Shaw <noden...@gmail.com> wrote: > Thanks, Las! > > Ok say I have a file in which there is string such as > > "(- (atan (bw-noise 902 2 0.7604615575402431 400 400)) (read-image-from-file > \"images/Dawn_on_Callipygea.png\"))" > > and another > > "version-0-0-1" > > and I have a namespace version-0-0-1 into which functions named atan etc. > are all :referred. I want to evaluate the expression in that particular > context, and not remain there when I'm done. > > -A > > > > On Mon, Dec 17, 2012 at 11:00 PM, László Török <ltoro...@gmail.com> wrote: >> >> ah, sorry, it's a bit early for me >> >> (in-ns (ns-name user-ns)) >> >> if you could post a simple example for the second part of your question I >> maybe able to help. >> >> Las >> >> Alan Shaw 2012. december 18., kedd napon a következőt írta: >> >>> Ah no, that puts me in a new user-ns namespace! Not what I wanted! >>> >>> >>> On Mon, Dec 17, 2012 at 10:51 PM, László Török <ltoro...@gmail.com> >>> wrote: >>>> >>>> Try (in-ns 'user-ns) >>>> >>>> Las >>>> >>>> On Dec 18, 2012 7:50 AM, "Alan Shaw" <noden...@gmail.com> wrote: >>>>> >>>>> user=> *ns* >>>>> #<Namespace user> >>>>> user=> (def user-ns *ns*) >>>>> #'user/user-ns >>>>> user=> user-ns >>>>> #<Namespace user> >>>>> user=> (in-ns user-ns) >>>>> ClassCastException clojure.lang.Namespace cannot be cast to >>>>> clojure.lang.Symbol clojure.lang.RT$1.invoke (RT.java:226) >>>>> >>>>> It appears I'm not understanding how namespaces are represented. >>>>> >>>>> Also, is it just wrong of me to want to remember a namespace I was >>>>> working in and try to go back to it later? >>>>> >>>>> The slightly larger context is: I'm saving an s-expression with >>>>> unqualified names in it into a file as a string. Also saving a string >>>>> indicating the name of the environment in which that string should be >>>>> (read >>>>> and) eval'ed so that the names will resolve to the appropriate functions. >>>>> Advice on managing this would be appreciated. >>>>> >>>>> -Alan Shaw >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Clojure" group. >>>>> To post to this group, send email to clojure@googlegroups.com >>>>> Note that posts from new members are moderated - please be patient with >>>>> your first post. >>>>> To unsubscribe from this group, send email to >>>>> clojure+unsubscr...@googlegroups.com >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/clojure?hl=en >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Clojure" group. >>>> To post to this group, send email to clojure@googlegroups.com >>>> Note that posts from new members are moderated - please be patient with >>>> your first post. >>>> To unsubscribe from this group, send email to >>>> clojure+unsubscr...@googlegroups.com >>>> For more options, visit this group at >>>> http://groups.google.com/group/clojure?hl=en >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To post to this group, send email to clojure@googlegroups.com >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> To unsubscribe from this group, send email to >>> clojure+unsubscr...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/clojure?hl=en >> >> >> >> -- >> László Török >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clojure@googlegroups.com >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- Baishampayan Ghose b.ghose at gmail.com -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en