Tuesday 15 March 2011

functional programming - Clojure: How to create a function at runtime -


I want to generate a fn entirely on the sequence (i.e. name and RGR symbols are ordered in sequence, Not in code) What is the best way to achieve this?

How can I implement the following functions?

  (defn gen-fn [name arg-symbols body] ... ...  

will be used like this:

  (Jean-FN "my-throw-name" (symbol "x") (symbol "y") (println "this  x =" x ")  

Note that the name, arg and body of the function are not coded, but the runtime can be decided

  (defn gen-fn [n as b] (let [n (symbol n) (vec as the map symbol)) fn-  

Some more uses:

 

Code> User => (Jean-F N "EFU" ["X"] '(print (XMP)) (printline (Ink))) #' User / FU user => (FU5) 5 6 void

However, I do not really like this approach. It really works harder: eval Why do you want to make global in runtime? On growing namespace and other ugly hiccups on the horizon. ..


No comments:

Post a Comment