This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-12
Channels
- # architecture (17)
- # babashka (13)
- # beginners (12)
- # calva (1)
- # cider (7)
- # clojure-bay-area (15)
- # clojure-europe (4)
- # clojure-norway (7)
- # datomic (7)
- # gratitude (5)
- # honeysql (7)
- # hyperfiddle (2)
- # introduce-yourself (4)
- # jobs-discuss (13)
- # juxt (2)
- # lsp (3)
- # malli (7)
- # practicalli (17)
- # rdf (8)
- # re-frame (9)
- # releases (1)
- # shadow-cljs (24)
- # spacemacs (15)
I've got a weird one for you. Trying to help a friend learn some Clojure. Using babashka 1.3.182. More in thread...
(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")
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 --------------------------------------------------------------
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
there is a line with (addone mylist) where mylist is a vector
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
what is in the stacktrace?