Fork me on GitHub
#babashka
<
2023-08-12
>
Nundrum16:08:40

I've got a weird one for you. Trying to help a friend learn some Clojure. Using babashka 1.3.182. More in thread...

Nundrum16:08:25

(defn hallo [title]
  (println "hello" title))
(hallo "Steve")
(hallo "world")
(type hallo)

(defn addone [x]
  (+ x 1))
(addone 2)
(+ 1 1)
(def n 10)
(println n)
(addone n)
(println *command-line-args*)
(def mylist [1 5 7 12 42 58])
(addone mylist)
(map addone mylist)
(first mylist)
(last mylist)
(rest mylist)
(conj mylist 5000)
(last (conj mylist 5000))
(count "world")

Nundrum16:08:17

Running that with bb returns

----- Error --------------------------------------------------------------------
Type:     java.lang.ClassCastException
Message:  clojure.lang.PersistentVector cannot be cast to java.lang.Number
Location: /home/robbie/bonjour.clj:8:3

----- Context ------------------------------------------------------------------
 4: (hallo "world")
 5: (type hallo)
 6: 
 7: (defn addone [x]
 8:   (+ x 1))
      ^--- clojure.lang.PersistentVector cannot be cast to java.lang.Number
 9: (addone 2)
10: (+ 1 1)
11: (def n 10)
12: (println n)
13: (addone n)

----- Stack trace --------------------------------------------------------------

Nundrum16:08:39

The error is really several lines down, where he tried to (addone mylist)

borkdude16:08:00

I get a similar error with clojure:

$ clj -M /tmp/dude.bb
hello Steve
hello world
10
nil
Execution error (ClassCastException) at user/addone ().
class clojure.lang.PersistentVector cannot be cast to class java.lang.Number (clojure.lang.PersistentVector is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')

Full report at:
/var/folders/j9/xmjlcym958b1fr0npsp9msvh0000gn/T/clojure-7696729073006534719.edn

Nundrum16:08:19

hah ok interesting

Nundrum16:08:48

Think I should open a bug report on that?

delaguardo16:08:27

there is a line with (addone mylist) where mylist is a vector

Nundrum16:08:29

Right. I just thought it weird the error output was not pointing to that line.

delaguardo16:08:13

it points to the function addone and gives you vector can not be cast to number. that is usually enough to get to the root cause

delaguardo16:08:47

what is in the stacktrace?

Nundrum16:08:12

Yeah, it's not a big deal. The stack trace points to the line number with the error. The context part just had me blinking at it for a minute.