--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/4bdd8dee-0b87-42a1-8d3a-4a2cf60f3aff%40googlegroups.com.
Hey Ru,Renaming x to anything will result in roughly the same error in your function. The problem is that your instance macro needs to know the classname at compile time. As x is a runtime variable, the compiler cannot see the literal value of x at compile time. Put another way, in your test function, with no other changes, you need a switch statement that tests if x is a known type and then calls the macro with the now-known-at-compile-time literal classname.An instance function that found the constructor of x via reflection and then called that is what you want here.
Chris
On Sat, Oct 19, 2019 at 8:03 AM ru <sor...@oogis.ru> wrote:
Ok, Matching Socks.--On what name should I replace the variable name "x" in the function definition so that the macro like it?
суббота, 19 октября 2019 г., 14:09:01 UTC+3 пользователь Matching Socks написал:The macro is a code generator, with which the compiler computes the actual definition of the "test" function. What's there is x, and the macro does not like x. The REPL definition of JLabel worked because JLabel was the literal argument. See https://clojure.org/reference/macros, which is subtle about this point, or the excellent book "Mastering Clojure Macros".
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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
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 clo...@googlegroups.com.
Macros manipulate program symbols. Macros fill the role that is filled by Perl scripts in the Java world, when they pre-process stuff (a database schema, or a gui model, for example) into actual Java code before you compile it. If a task could not be solved by pre-processing the source code before the program starts to run, then it is not a task for a macro.On the bright side, using Java reflection is less tedious in Clojure than it is in Java.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/2c56ec62-9908-40b8-aacc-aecaf157049c%40googlegroups.com.
(defn itest [x] (macroexpand-1 '(instance x)))
=> #'user/itest
(itest java.lang.String)
=> (new x)
(defn itest [x] (new x))
Syntax error (IllegalArgumentException) compiling new at [...]
Unable to resolve classname: x
(defn itest [x & args](let [cnstr (.getConstructor x (into-array java.lang.Class [String]))](.newInstance cnstr (into-array java.lang.Object args))))=> #'user/itest(itest java.lang.String "Hello")=> "Hello"
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/E0B8D5A1-AC56-4FD6-BAC9-220E628FC510%40chartbeat.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 clo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/2c56ec62-9908-40b8-aacc-aecaf157049c%40googlegroups.com.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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
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 clo...@googlegroups.com.