Re: Little namespace question

2012-12-19 Thread Alan Shaw
Oh! yes it does! -A On Wed, Dec 19, 2012 at 6:39 PM, Dave Ray wrote: > It does, right? > > > On Wednesday, December 19, 2012, Alan Shaw wrote: > >> But returning the evaluation was a requirement... >> >> >> On Wed, Dec 19, 2012 at 2:58 PM, Alan Shaw wrote: >> >> No, there was no requirement

Re: Little namespace question

2012-12-19 Thread Dave Ray
It does, right? On Wednesday, December 19, 2012, Alan Shaw wrote: > But returning the evaluation was a requirement... > > > On Wed, Dec 19, 2012 at 2:58 PM, Alan Shaw wrote: > > No, there was no requirement that it be a macro. Thanks! > > -A > > > > On Wed, Dec 19, 2012 at 7:40 AM, Dave Ray wro

Re: Little namespace question

2012-12-19 Thread Dave Ray
A function seems to work fine unless I don't understand your requirement: ; normal version that takes code forms and symbols (defn eval-in [code ns] (let [old (-> *ns* str symbol)] (try (in-ns ns) (eval code) (finally (in-ns old) ; sugary

Re: Little namespace question

2012-12-19 Thread Alan Shaw
Thanks again. This version is easier for my non-macro brain to follow. -A On Wed, Dec 19, 2012 at 8:58 AM, juan.facorro wrote: > The following example shows an implementation of *eval-in* as a function. > > There are a some *println* added to show the namespace where the code is > running at e

Re: Little namespace question

2012-12-19 Thread juan.facorro
The following example shows an implementation of *eval-in* as a function. There are a some *println* added to show the namespace where the code is running at each point. ;; (ns another-ns) (defn X [w h] {:w w :h h}) ;; (ns this-ns) (defn eval-in [code

Re: Little namespace question

2012-12-18 Thread Alan Shaw
As an aside, I'm curious about whether this could have been implemented without a macro. -A On Dec 18, 2012 11:06 PM, "Alan Shaw" wrote: > Thanks very much Juan, that's some good study material for me. > > -A > On Dec 18, 2012 10:45 PM, "juan.facorro" wrote: > >> The macro sees it arguments a

Re: Little namespace question

2012-12-18 Thread Alan Shaw
Thanks very much Juan, that's some good study material for me. -A On Dec 18, 2012 10:45 PM, "juan.facorro" wrote: > The macro sees it arguments as *symbols* and does not resolve to the > corresponding *var* until evaluation, so the value for the local *code* var > in the macro is actually the *

Re: Little namespace question

2012-12-18 Thread juan.facorro
The macro sees it arguments as *symbols* and does not resolve to the corresponding *var* until evaluation, so the value for the local *code* var in the macro is actually the *symbol** generator.* The *eval-in* macro uses the *read-string* function to evaluate the code you provide, this function

Re: Little namespace question

2012-12-18 Thread Alan Shaw
>From yesterday: (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))]

Re: Little namespace question

2012-12-18 Thread Alan Shaw
Now I do, and the macro worked! I believe I have a problem using the macro from a function, but leaving that for tomorrow. Thanks BG! -A On Tue, Dec 18, 2012 at 12:19 AM, Baishampayan Ghose wrote: > Do you have target ns "clevolution.version.version0-1-1" required? > > -BG > > On Tue, Dec 18,

Re: Little namespace question

2012-12-18 Thread Baishampayan Ghose
Do you have target ns "clevolution.version.version0-1-1" required? -BG On Tue, Dec 18, 2012 at 1:38 PM, Alan Shaw wrote: > BG, > The macro doesn't seem to do the trick. The function X is interned in the > target namespace, but: > > user=> (def image (eval-in "(X 400 400)" > "clevolution.version.

Re: Little namespace question

2012-12-18 Thread Alan Shaw
BG, The macro doesn't seem to do the trick. The function X is interned in the target namespace, but: user=> (def image (eval-in "(X 400 400)" "clevolution.version.version0-1-1")) CompilerException java.lang.RuntimeException: Unable to resolve symbol: X in this context, compiling:(NO_SOURCE_PATH:1)

Re: Little namespace question

2012-12-17 Thread Alan Shaw
Oh yes, the something.something is fixed so I can just prepend it, thanks. (Hadn't noticed your macro takes the ns as a string!) -A On Mon, Dec 17, 2012 at 11:47 PM, Baishampayan Ghose wrote: > Alan, > > What you're asking for is to derive the ns "clojure.core" given only > "core". Not sure i

Re: Little namespace question

2012-12-17 Thread Baishampayan Ghose
Alan, What you're asking for is to derive the ns "clojure.core" given only "core". Not sure if that's possible. The namespace constitutes the whole dotted structure and not just the last component, I am afraid. If the actual ns is something.something.version-0-1-1, then you need the string "some

Re: Little namespace question

2012-12-17 Thread Alan Shaw
Thanks BG, I'm trying that. But I don't think it addresses how to get from the string "version-0-1-1" to the namespace something.something.version-0-1-1. How can I do that? -A On Mon, Dec 17, 2012 at 11:26 PM, Baishampayan Ghose wrote: > Alan, > > Something like this might work for you - > > (

Re: Little namespace question

2012-12-17 Thread Baishampayan Ghose
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

Re: Little namespace question

2012-12-17 Thread Alan Shaw
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 :re

Re: Little namespace question

2012-12-17 Thread László Török
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! > > >

Re: Little namespace question

2012-12-17 Thread Alan Shaw
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 wrote: > Try (in-ns 'user-ns) > > Las > On Dec 18, 2012 7:50 AM, "Alan Shaw" wrote: > >> user=> *ns* >> # >> user=> (def user-ns *ns*) >> #'user/user-ns >> user=> user-ns >> # >> u

Re: Little namespace question

2012-12-17 Thread László Török
Try (in-ns 'user-ns) Las On Dec 18, 2012 7:50 AM, "Alan Shaw" wrote: > user=> *ns* > # > user=> (def user-ns *ns*) > #'user/user-ns > user=> user-ns > # > user=> (in-ns user-ns) > ClassCastException clojure.lang.Namespace cannot be cast to > clojure.lang.Symbol clojure.lang.RT$1.invoke (RT.java

Little namespace question

2012-12-17 Thread Alan Shaw
user=> *ns* # user=> (def user-ns *ns*) #'user/user-ns user=> user-ns # 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