Skip to content, Skip to search


Clojure Scripting

605 bytes added, 07:10, 19 September 2009
explained pretty printing
The above code translated from lisp code at [ funcall blog]. Thanks [ Joe Marshall] for sharing this perl.
<h3>Pretty printing an array or a map</h3>
Suppose we create a primitive array of length 10:
<source lang="lisp">
user=> (def pa (make-array Integer/TYPE 10))
If we print it, we get:
<source lang="lisp">
user=> (println pa)
#<int[] [I@169bc15>
... which is not very useful. Instead, let's pretty print it.
First, import the function <i>pprint</i> (and many other functions) from clojure-contrib pprint namespace:
<source lang="lisp">
user=> (use 'clojure.contrib.pprint)
Then, use it:
<source lang="lisp">
user=> (pprint pa)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Emailconfirmed, uploaders