(defn
trim-newline
"Removes all trailing newline \\n or return \\r characters from\n string. Similar to Perl's chomp."
[s]
(loop
[index (.-length s)]
(if
(zero? index)
""
(let
[ch (get s (dec index))]
(if
(or (identical? \newline ch) (identical? \return ch))
(recur (dec index))
(.substring s 0 index))))))