I have a few functions that deal with lists. I have an even function which accepts a list parameter and gets the even indexes of the list. The odd function does the same thing but with odd indexes. I also have another function that merges two sorted lists called merge-list that takes two lists as parameters.
The problem is with the function I am writing now: merge-sort.
Here is what I have:
(defn merge-sort [lis]
(if (empty? (rest lis))
lis
(merge-list (merge-sort (odd(lis))) (merge-sort (even(lis))))))))
For some reason I keep getting the error
java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn
I can pass the odd function rest lis like this (odd(rest lis))
(same with even). It runs fine but that obviously doesn't give me the solution I want.
I'm very new to Clojure so any tips would be appreciated. Thanks.
(odd lis)
and (even lis)
, not (odd (lis))
. You want to pass it as a parameter, not call it as a function and then pass the result of that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With