I have the following code, which is a part of Clojure katas:
(ns alphabet-cipher.coder)
(def letters (map char (range 97 123)))
(defn rotate
[n]
(-> n
(split-at letters)
(reverse)
(flatten)))
(def cipher-map
(apply hash-map
(mapcat #(list (keyword (str %1)) (rotate %2))
letters (range 0 26))))
(defn encode
[keyword message]
(apply str (map #(nth ((keyword (str %2)) cipher-map)
(.indexOf (:a cipher-map) %1))
keyword message)))
(encode "meetmebythetree" "sconessconessco")
The code itself doesn’t matter.
What matters is that upon executing this code in repl i get the following:
CompilerException java.lang.ClassCastException: java.base/java.lang.String cannot be cast to clojure.lang.IFn, compiling
What is going on? If I remove arguments in encode function and hardcode both bindings it works just fine, but when passing the arguments it just crashes. encode
is definitely a function.