stringclojurecompojurehiccupnoir

how to return a clojure function as a string


is there any way to return a clojure function as a string? I am making some online documentation and I would really like to be able to add code into the html by somehow evaluating a function into text.

thanks


Solution

  • Take a look at the source-fn function from the clojure.repl namespace:

    Usage: (source-fn x)

    Returns a string of the source code for the given symbol, if it can find it. This requires that the symbol resolve to a Var defined in a namespace for which the .clj is in the classpath. Returns nil if it can't find the source. For most REPL usage, 'source' is more convenient.

    Example: (source-fn 'filter)