functionclojuremetaprogrammingevaldefn

How to defn a function from string in Clojure?


I'd like to do this (in REPL or anywhere)

(defn (symbol "print-string") [k] (println k))

and then be able to do

(print-string "lol")

Or, if there is any other way to create defn from custom strings in macroses, could you push me into the right direction please?


Solution

  • (defmacro defn-with-str [string args & body]
     `(defn ~(symbol string) ~args ~@body))
    
    (defn-with-str "print-string" [k] (println k))
    
    (print-string "lol")