Dear Clojure users and team! I have defined a macros to get an instance of arbitrary Java class and tried to test it:
ru@ru-iMacMint:~$ lein repl nREPL server started on port 46225 on host 127.0.0.1 - nrepl://127.0.0.1:46225 WARNING: cat already refers to: #'clojure.core/cat in namespace: net.cgrand.regex, being replaced by: #'net.cgrand.regex/cat REPL-y 0.3.7, nREPL Clojure 1.8.0 Java HotSpot(TM) 64-Bit Server VM 11.0.2+9-LTS Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e user=> (defmacro instance [x & args] `(new ~x ~@args)) #'user/instance user=> (instance javax.swing.JLabel "Ru") #object[javax.swing.JLabel 0x53754b7 "javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=Ru,verticalAlignment=CENTER,verticalTextPosition=CENTER]"] user=> (defn test [x] (let [i (instance x)] i)) WARNING: test already refers to: #'clojure.core/test in namespace: user, being replaced by: #'user/test CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: x, compiling:(null:1:24) user=> (defn itest [x] (let [i (instance x)] i)) CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: x, compiling:(null:1:25) user=> Why I can't use my macro in a function definition? Any help would be greatly appreciated. Sincerely, Ru. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/d7482483-633e-40b7-9d6a-f5444a86dbdf%40googlegroups.com.