I've just begun to teach myself clojure and I'm having fun. However trouble began when I began to exec this function I wrote!
It's a simple function that accepts multiple number of arguments & returns the difference between the last and the first arguments.
(defn diff-last-first
"gets the difference between the last & the first arguments"
[& args]
(- (get args (- (count args) 1)) (get args 0)))
I know that I can simply use the last function to get the last element of args, but I'm not able to understand why this is throwing a NullPointerException when I execute
(diff-last-first 1 2 3)
(get (list :foo) 0)
evaluates to nil.Lists are not supposed to be accessed by index: it is a common design decision in Clojure to prevent such inefficiencies.