I agree, that's not the expected behavior. The form is just data, it doesn't have to be valid code. Since '(Object) is not a macro (Object is a Symbol there, not a class) it should just return the form just like (identity) does: user=> (identity '(Object)) (Object)
But macroexpand-1 does some extra work for the interop sugar. I suspect that the error comes when it tries to work out a static member. user=> (macroexpand-1 '(.length "s")) (. "s" length) user=> (macroexpand-1 '(Boolean/TRUE)) (. Boolean TRUE) user=> (macroexpand-1 '(String.)) (new String) On Aug 31, 3:17 pm, Frederic Koehler <f.koehler...@gmail.com> wrote: > If you were to say, (macroexpand '(foo)), it returns (foo), even if it's > not defined in the context, so I'd say it's a little unexpected. > > More annoying is the result this has on macroexpand-all, which breaks > because of this weird behaviour: > > (use 'clojure.walk) > (walk/macroexpand-all '(let [Object (fn [])] (Object))) > > java.lang.RuntimeException: java.lang.Exception: Expecting var, but > Object is mapped to class java.lang.Object (NO_SOURCE_FILE:0) > > Of course, this example is somewhat (not super-) obvious, but in more > complex cases it could be fairly annoying. > > > > On Tue, 2010-08-31 at 08:14 +0200, Konrad Hinsen wrote: > > On 30 Aug 2010, at 23:18, Frederic Koehler wrote: > > > > I accidentally noticed this: > > > > On clojure 1.2, macroexpanding with a function name which is a class, > > > causes this ugly error: > > > >> (macroexpand '(Object)) > > > java.lang.Exception: Expecting var, but Object is mapped to class > > > java.lang.Object (repl-1:2) > > > > when presumably it should just give '(Object). > > > I have no clue for any actual use cases of naming your functions after > > > classes, but: > > > (let [Object (fn [] 3)] (Object)) > > > is technically valid clojure code, so macroexpand shouldn't just > > > die... > > > You are right that > > > (let [Object (fn [] 3)] (Object)) > > > is valid Clojure code, and it works as expected. However, > > > (Object) > > > is not a valid expression. It fails with exactly the same error > > message as > > > (macroexpand '(Object)) > > > so I'd say this is consistent behaviour. > > > Konrad. > > > -- > > 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- Hide quoted text - > > - Show quoted text - -- 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