clojure - How do I pass variables as variable names to a function? -
I want to be able to do the following pseudo-coding:
- Pass the symbol a .
- Pass in Pass B.
- Pass in expression using A and B
- As I changed the value of A and B, print out the output of C every moment.
Ideally, I want a signature to see it:
(runner AB (+ AB))
< P> But I'm not sure I'm passing it correctly ... I have tried to change the function (Runner 'A' B (+ 'A') B))
And this is a more complex example:
(runner 'A' B (+ (* 'A' B) 'A))
But before stepping into the runner, it does one on 'a and' b.
Here is my first rip on some closures:
(rival runner [abc] (([i (grade 10) j (range 10)] (printlen i.जे. Siz))
What is the concept of closure I am missing?
The debate is always evaluated before the function function is called. If you want to postpone the assessment or want to represent some calculation or code in the form of the object , Then you have a few options:
- Use a function (see my code below)
- Bind the macro and some code into some code that generates macros
- Pass the code as a quoted list, and using
eval
.
is a function that you call 99% 1% of the time, you want macros. You do not need eval
any time, unless you make code on the runtime.
user> (Defender runner [F] (Dozak [A (Range 3) B (Range 3)] (printlean ABC (FA) B))) # # User / Runner User & gt; (Runner (fn [xy] (+ xy)) 0 0 1 1 1 2 2 1 1 1 1 1 2 1 2 3 2 0 2 2 1 3 2 2 4
It can also be written as a (Runner # (+% 1% 2)
or simply (Runner +)
.
No requirement In the function, to pass the " a
" and " b
" in the form of the argument. For doseq
and / Code> Originally named Skoda for its own local, things, there is no reason that they should use
is the same as I a
and b
, any The name will be < Code> fn x
and y
are used here because of no difference.
I have a
and could also be used in
in fn
body, but they have an different a
and b
sees doseq
, you may want to read it if it does not make sense.
Comments
Post a Comment