Search code examples
clojure

clojure app config files - spit output of pprint s-expression?


I need config files for a clojure application I'm building. They should be easy enough for a user to modify in a text editor and convenient for my program to read.

I was thinking about serializing s-expressions and using spit to put it into a config file in the users home directory, but I want to pprint the data i spit so it looks a little more friendly to human eyes.

How can I spit the output of pprint in clojure?

Is my thought process correct on using serialized s-expressions as a config file in clojure?


Solution

  • you have a couple of options. First, pprint accepts an optional writer as a second parameter or you can spit the result of with-out-str: (spit "f.txt" (with-out-str (pprint ..))

    I think serialized s-expressions are a reasonable choice as long as they are treated just as data.