small medium large xlarge

Generic-user-small
15 Mar 2017, 13:51
Thalys (1 post)

I am trying to run a test of the book but it does not work, I would like to see if anyone could help me.

MBP-de-Thalys:~ thalys$ lein version Leiningen 2.7.1 on Java 1.8.0_102 Java HotSpot(TM) 64-Bit Server VM MBP-de-Thalys:~ thalys$ lein repl nREPL server started on port 57391 on host 127.0.0.1 - nrepl://127.0.0.1:57391 REPL-y 0.3.7, nREPL 0.2.12 Clojure 1.8.0 Java HotSpot(TM) 64-Bit Server VM 1.8.0_102-b14 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e

user=> (defn ^long integer-sum-to [^long n] #_=> (loop [i 1 sum 0] #_=> (if (<= i n) #_=> (recur (inc i) (+ i sum)) #_=> sum))) #’user/integer-sum-to user=> (dotimes [_ 5] (time (integer-sum-to 10000)))

AbstractMethodError Method user$integer_sum_to.invokePrim(J)Ljava/lang/Object; is abstract user/integer-sum-to (form-init8659122168599004042.clj:-1) user=>

Alex_head_pragsmall
22 May 2017, 16:07
Alex Miller (20 posts)

The ^long return type parameter is being interpreted incorrectly - this has always been wrong here but it was previously ignored. To fix, move the ^long return type hint before the argument vector:

(defn integer-sum-to ^long [^long n]
  (loop [i 1 sum 0]
    (if (<= i n)
      (recur (inc i) (+ i sum))
      sum)))

This will be fixed in the 3rd edition.

You must be logged in to comment