<commit_before>(ns pp-server.format.clojure-pp
  (:require [clojure.tools.reader :as r]
            [clojure.pprint :refer [write code-dispatch simple-dispatch]]))

(def dispatch-mode {:clojure code-dispatch :edn simple-dispatch})

(defn- str-to-literal!
  "Takes valid clojure as input and transforms it to a clojure literal for
  formating."
  [string]
  (r/read-string string))

(defn- format-literal!
  "Takes a literal and formats it using the built in clojure.pprint/write
  function. Returns a formatted literal."
  [literal tipe]
  (write literal
         :pretty true
         :stream nil
         :dispatch ((keyword tipe) dispatch-mode)))

(defn- literal-to-str!
  "Takes valid formatter clojure literal as input and transforms it to a string
  for return to webapp UI"
  [literal]
  (str literal))

(defn format-clj!
  [input tipe]
  (let [in-lit    (str-to-literal! input)
        formatted (format-literal! in-lit tipe)
        out-str   (literal-to-str! formatted)]
        (println out-str)
        out-str))<commit_msg>Comments on the clojure-pp public function format-clj!.<commit_after>(ns pp-server.format.clojure-pp
  (:require [clojure.tools.reader :as r]
            [clojure.pprint :refer [write code-dispatch simple-dispatch]]))

(def dispatch-mode {:clojure code-dispatch :edn simple-dispatch})

(defn- str-to-literal!
  "Takes valid clojure as input and transforms it to a clojure literal for
  formating."
  [string]
  (r/read-string string))

(defn- format-literal!
  "Takes a literal and formats it using the built in clojure.pprint/write
  function. Returns a formatted literal."
  [literal tipe]
  (write literal
         :pretty true
         :stream nil
         :dispatch ((keyword tipe) dispatch-mode)))

(defn- literal-to-str!
  "Takes valid formatter clojure literal as input and transforms it to a string
  for return to webapp UI"
  [literal]
  (str literal))

(defn format-clj!
  "Clojure formatting function that takes a unformatted-input and format type
  and transforms it into a formatted output using clojure.pprint/write."
  [input tipe]
  (let [in-lit    (str-to-literal! input)
        formatted (format-literal! in-lit tipe)
        out-str   (literal-to-str! formatted)]
        (println out-str)
        out-str))
{'fraction_non_alphanumeric': 0.10596026490066225, 'fraction_numerical': 0.0, 'mean_word_length': 3.1275045537340618, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5705069', 'n_tokens_mistral': 753, 'n_tokens_neox': 735, 'n_words': 238}