Thank you, Marc!
I will try to use your example to develop more general "instance" function.
Sincerely,
Ru
воскресенье, 20 октября 2019 г., 15:35:48 UTC+3 пользователь mlimotte
написал:
>
> Hey Ru,
>
> I'd also add that `new` is a special form, not a function. It is
> evaluated at compile-ti
Hey Ru,
I'd also add that `new` is a special form, not a function. It is evaluated
at compile-time, which is why the macro doesn't work. You can also try
macro-expansion to see what's going on:
(defn itest [x] (macroexpand-1 '(instance x)))
=> #'user/itest
(itest java.lang.String)
=> (new x)
Macros also allow you to create a dsl to make your code easier to use or
understand by obfuscating away bits. For example a macro that times a function
call by proxying the call or wrapping a call to defn.
That said, I consider many uses of macros that I’ve seen to be antipatterns
that lead to
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 b
суббота, 19 октября 2019 г., 17:15:23 UTC+3 пользователь Chris Nuernberger
написал:
>
> 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 variab
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
f
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
> defin
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
sub
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.