2012. január 20., péntek

Clojure REPL: use pretty print


When displaying a hierarchical data structure consisting of lists, sets and maps, use the clojure.pprint package. You can dynamically rebind options to change the default number base, desired column width, etc. Here are some examples:


 user> (def posts [{:id 1000 :summary "This is the first post" :tags #{"java" "clojure" "pprint"}}
       {:id 1001 :summary "
Very very very very very very very very very very long summary" :tags #{"java" "clojure" "pprint"}}])
#'user/posts


 user> (use 'clojure.pprint)
nil


 user> (pprint posts)
[{:summary "This is the first post",
  :id 1000,
  :tags #{"java" "clojure" "pprint"}}
 {:summary "
Very very very very very very very very very very long summary",
  :id 1001,
  :tags #{"java" "clojure" "pprint"}}]
nil


 user> (binding [*print-base* 2]
    (pprint posts))
[{:summary "This is the first post",
  :id 1111101000,
  :tags #{"java" "clojure" "pprint"}}
 {:summary
  "Very very very very very very very very very very long summary",
  :id 1111101001,
  :tags #{"java" "clojure" "pprint"}}]
nil


 user> (binding [*print-right-margin* 30]
    (pprint posts))
[{:summary
  "This is the first post",
  :id 1000,
  :tags
  #{"java"
    "clojure"
    "pprint"}}
 {:summary
  "Very very very very very very very very very very long summary",
  :id 1001,
  :tags
  #{"java"
    "clojure" "pprint"}}]
nil

1 megjegyzés:

  1. The first American video slot machine to offer a "second screen" bonus round was Reel ’Em In, developed by WMS Industries in 1996. This kind of machine had appeared in Australia from at least of|no much less than} 1994 with the Three Bags Full recreation. With {this kind of|this type of|this type of} machine, the display changes to 1xbet supply a unique recreation by which a further payout could also be} awarded.

    VálaszTörlés