Creating printf functionality in Clojure and ClojureScript


#1

Hi all. I’m just getting started with Clojure although I have been a long time fan of Lisp and functional programming.

I am trying to get printf functionality that will work in both Clojure and ClojureScript. I understand the underlying implementation of Java vs the Google closure compiler makes it impractical to implement printf or format for ClojureScript. I was wondering what techniques the Clojure/ClojureScript community uses to format printing in both languages.

I appreciate any help or advice.

– Lance.


#2

I just had this issue today, and I ended up using “cl-format” https://clojuredocs.org/clojure.pprint/cl-format - I had to format a number in a CLJ and CLJS way https://github.com/l3nz/cli-matic/blob/master/examples-cljs-planck/toycalc.cljs


#3

Thanks, @l3nz, I will take a look at cl-format today.

Follow up question…I thought I read somewhere on this site that there is a way to mark an accepted solution but I can’t find it in the UI.

How do I mark this solution as accepted?


#4

I don’t know. I also miss a decent tutorial/cheatsheet for cl-format - anybody has pointers to share?


#5

This is what I used http://www.gigamonkeys.com/book/a-few-format-recipes.html