Fork me on GitHub
#babashka
<
2023-02-14
>
Jakub Šťastný17:02:48

Does babashka not respect toString?

borkdude17:02:06

Seems like a bug, issue welcome

Jakub Šťastný17:02:37

@U04V15CAJ is what I'm doing with print-method and toString not commonly used? I'm surprised about this toString bug, so it makes me think I'm probably doing something that's not overly common? Otherwise someone would surely discover it by now.

Jakub Šťastný17:02:26

Like I'm coming from Ruby/JS and in Ruby it's very common to define its variant of toString (`inspect` and to_s) for objects. So I wonder whether it's much of a pattern in Clojure, but since it's supported...

borkdude17:02:17

deftype isn't frequently used, only for very low level constructs. avoid it if you don't need it

borkdude17:02:56

The mantra in Clojure is "just use maps"

👍 2
borkdude17:02:06

It seems that for defrecord it does work in bb:

user=> (defrecord Dude2 [] Object (toString [_] "dude2"))
user.Dude2
user=> (.toString (->Dude2))
nil
user=> (str (->Dude2))
"dude2"
but like we saw yesterday, the java interop doesn't work properly

borkdude17:02:35

I pushed the toString fix with str to master now, still need to look into the interop case

Jakub Šťastný17:02:54

Oh wow, cheers! That was fast.

borkdude17:02:01

yeah, it was just a typo somewhere

borkdude17:02:30

When the current build finishes, you can install the new version with:

bash <(curl ) --dev-build --dir /tmp