clojure - How do I pass variables as variable names to a function? -


I want to be able to do the following pseudo-coding:

  1. Pass the symbol a .
  2. Pass in Pass B.
  3. Pass in expression using A and B
  4. 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:

  1. Use a function (see my code below)
  2. Bind the macro and some code into some code that generates macros
  3. 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 a and b , any The name will be < Code> fn is the same as I 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

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -