Absolutely incredible. I guess the pitiful little guy thought that he
had to cobble together that hideous mess in order to avoid
traversing the string more than once.
And that bonehead was considered a Commune Lisp guru.
Tells you a lot about Commune "Lisp", doesn't it?
Clojure:
;; Traverses the string no more than once.
(defn can-invert [[chr & more] prev-case result]
(if-not chr
result
(let [chr-case (cond (Character/isUpperCase chr) 'up
(Character/isLowerCase chr) 'low
true false)]
(cond
(and prev-case chr-case (not= prev-case chr-case)) false
(= 'up chr-case)
(can-invert more chr-case (str result (Character/toLowerCase chr)))
(= 'low chr-case)
(can-invert more chr-case (str result (Character/toUpperCase chr)))
true (can-invert more prev-case (str result chr))))))
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
He was obviously concerned with efficiency, so he didn't fall into the
trap of coding a tail-recursive solution in language without tail-call
optimization.