On Mon, Dec 22, 2008 at 8:08 AM, Randall R Schulz <rsch...@sonic.net> wrote:
>
> On Monday 22 December 2008 05:55, Mark Volkmann wrote:
>> On Sun, Dec 21, 2008 at 3:44 PM, Stephen C. Gilardi wrote:
>> > ...
>>
>> I thought that every symbol and keyword was in some namespace,
>> defaulting to the current namespace when the symbol or keyword is
>> defined. Since the default namespace in the REPL is user, that's what
>> I expected. I get the same error though with any symbol that I def.
>> For example,
>>
>> (def n 1)
>> (namespace n)
>> java.lang.IncompatibleClassChangeError (NO_SOURCE_FILE:0)
>>
>> Shouldn't the namespace of n be user?
>
> Starting with this:
>
> user=> (doc namespace)
> -------------------------
> clojure.core/namespace
> ([x])
>  Returns the namespace String of a symbol or keyword, or nil if not
> present.
>
>
> Note that namespace is a function, not a macro or special form. That
> means its arguments are _always_ evaluated before it is invoked. So in
> the example you gave is the same as:
>
> user=> (namespace 1)

Ah, that makes sense.

> java.lang.IncompatibleClassChangeError (repl-1:5)

But this doesn't seem like an appropriate error message to receive.
>From the javadoc, that means "The definition of some class, on which
the currently executing method depends, has since changed."

> Presumably (as I mentioned earlier) you want to examine the Var
> associated with the name "n" (as you def'ed in your example):
>
> user=> ^#'n
> {:ns #<Namespace user>, :name n, :file "repl-1", :line 6}
>
> user=> (str (:ns ^#'n))
> "user"
>
>
> You could create a macro to do this:
>
> (defmacro var-namespace-name [v] `(str (:ns ^(var ~v))))
>
> user=> (var-namespace-name n)
> "user"

Thanks for the explanation!

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to