This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-13
Channels
- # announcements (14)
- # babashka (13)
- # beginners (25)
- # biff (7)
- # calva (36)
- # clj-kondo (22)
- # clojure (31)
- # clojure-austin (1)
- # clojure-europe (12)
- # clojure-losangeles (4)
- # clojure-nl (1)
- # clojure-norway (61)
- # clojure-uk (4)
- # clojurescript (3)
- # datomic (24)
- # events (1)
- # humbleui (9)
- # leiningen (9)
- # lsp (30)
- # malli (3)
- # missionary (15)
- # off-topic (5)
- # re-frame (4)
- # reitit (7)
- # releases (2)
- # remote-jobs (4)
- # rewrite-clj (8)
- # ring-swagger (2)
- # sci (6)
- # xtdb (2)
- # yamlscript (3)
What are my options for translating this sort of thing into babashka?:
(deftype MyString [^String s]
Object
(^String toString [_this] s))
I see that I can’t do it directly because adding methods on a SciType is not allowed. I’m trying to find a way to differentiate between strings and a different sort of string.The error looks like:
clojure.lang.ExceptionInfo: Method toString on class sci.impl.deftype.SciType not allowed!
{:type :sci/error, :line nil, :column nil, :file "<expr>"}
at sci.impl.utils$throw_error_with_location.invokeStatic (utils.cljc:43)
interesting
user=> (deftype MyString [s] Object (toString [_] (str "special " s)))
user.MyString
user=> (MyString. "foo")
#object[user.MyString 0x688bd4b7 "special foo"]
user=> (str *1)
"special foo"
For the sake of completeness, I figured out it was from calling .toString
on the deftype. str
works though, so issue’s solved
Seems that require
and if
do not play nicely together, at least when the playground is a Babashka script.
The only difference among bb1.clj
and bb2.clj
is that bb2.clj
executes its require
s inside an if
form.
The result is that bb1.clj
correctly executes without problems, and bb2.clj
aborts with a clojure.lang.ExceptionInfo
with Message: Could not resolve symbol: fancy/print-table
.
Why? Is it intentional?
(Note: I do not have a real need to require
inside an if
. I stumbled by accident into this behavior, and would like to understand it.)
Thanks! This scenario serves to teach us that incidental complexity cannot be totally avoided. It can only be pushed away a bit.
there is a library, https://github.com/clj-commons/digest, but you can also just use the Java API for this directly