0

Outside of the function, the code works as expected, but in the following code it returns exception on a test site [Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn]

How can I keep the function structure & get the results to print?

(defn sumTerm [hi lo] 
(if (< hi lo)
    (0)
    (let [
        terms (quot hi lo)
        tb (+ terms 1)
    ]
    (quot (* lo terms tb) 2)
    )             
))

let [
     ln 27
     a (sumTerm ln 4)
     b (sumTerm ln 7)
     abc (- (+ a b) (sumTerm ln 28))
 ]
 (println " abc= "(str abc))
1
  • 1
    What should this code do? Can you provide some test cases (input -> expected output)? And what is (now not defined) ln? Commented Nov 19, 2022 at 22:27

1 Answer 1

2

It cannot work as expected unless you never hit the (< hi lo)'s "then" branch, because you're trying to call 0 as a function by wrapping it in parentheses.

Try replacing (0) with just 0.

Sign up to request clarification or add additional context in comments.

1 Comment

That solved the issue. Thank you! My real function now resolves all Euler test cases. ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.