This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-13
Channels
- # aleph (6)
- # announcements (10)
- # asami (3)
- # babashka (111)
- # babashka-sci-dev (20)
- # beginners (28)
- # calva (28)
- # clj-http (2)
- # clj-kondo (23)
- # cljs-dev (16)
- # cljsrn (23)
- # clojure (116)
- # clojure-czech (3)
- # clojure-europe (33)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (5)
- # clojurescript (41)
- # community-development (2)
- # cursive (5)
- # datahike (4)
- # datomic (13)
- # figwheel-main (3)
- # fulcro (11)
- # google-cloud (1)
- # gratitude (8)
- # hyperfiddle (14)
- # jobs (2)
- # lsp (22)
- # malli (4)
- # off-topic (4)
- # other-languages (4)
- # pathom (13)
- # portal (40)
- # rdf (11)
- # reitit (1)
- # sci (15)
- # shadow-cljs (7)
- # specter (1)
- # sql (6)
- # xtdb (4)
hey! I’m having difficulty adding metosin/ring-swagger
and metosin/ring-swagger-ui
as a dep to my bb script
{...
:deps {metosin/ring-swagger {:mvn/version "0.26.2"}
metosin/ring-swagger-ui {:mvn/version "4.5.0"}}
...}
is it possible at all with babashka?
thanks!I’m trying to create a swagger file describing the http endpoints supported by the babashka project I’m working in. but I cannot bring the necessary swagger deps in, I get the following error, even in a bb repl:
user=> (require '[babashka.deps :as deps])
nil
user=> (deps/add-deps '{metosin/ring-swagger {:mvn/version "0.26.2"}})
nil
user=> (require '[ring.swagger.swagger2 :as swagger2])
Could not resolve symbol: clojure.lang.Compiler/CHAR_MAP [at schema/utils.clj:50:3]
yeah, the issue is indeed a bit different 🙂
java.lang.IllegalArgumentException: No matching field found: CHAR_MAP for class clojure.lang.Compiler [at schema/utils.clj:55:8]
That's still not the error that I'm seeing though. I'm seeing:
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: deftype
Phase: analysis
I'm looking more into the issue. The first issue is getting schema.core to work, which has a deftype
. But with some hacking I got it to work:
$ clojure -M:babashka/dev -e "(require '[schema.core :as s]) (def schema {:foo s/Int}) (prn (s/validate schema {:foo 1})) (prn (s/validate schema {:foo :bar}))"
{:foo 1}
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Value does not match schema:
So, the short term answer is, it doesn't work right now and I don't know what will come after schema.core works. I expect more issues, since there are more libraries that aren't supported in bb in there. It will definitely be cool to make schema.core work in bb though, so I'll look deeper into that.
Lol, with some hacking I got schema.core
to work in babashka:
$ clojure -M:babashka/dev -e "(require '[schema.core :as s]) (def schema {:foo s/Int}) (prn (s/validate schema {:foo 1})) (prn (s/validate schema {:foo :bar}))"
{:foo 1}
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Value does not match schema:
I'm hitting a limit with the validation of records, since records are implemented very differently in SCI (since SCI does not create new classes). Would schema still be useful in bb, without the record support?
This is the success ratio now:
{:test 94, :pass 477, :fail 27, :error 19, :type :summary}
I'm trying to port a lib to bb, but I it seems that calling with-meta
on a record casts the type to sci.impl.records.SciRecord
and it breaks the internals of the lib. Is there any way to overwrite the with-meta
behavior so it keeps the original type like in clj?
(defrecord Person [name])
(def person (map->Person {:name "Smith"}))
(type person)
; user.Person
(prn person)
; #user.Person{:name "Smith"}
; so far so good
(def person-wm (with-meta person {:meta true}))
(type person-wm)
; sci.impl.records.SciRecord
; there is also an issue with printing the record
(prn person-wm)
: java.lang.Class cannot be cast to clojure.lang.Named user
There might be a better way for SCI to store the metadata, in a separate field probably, but that would make printing maps behave like:
{:a 1 :__sci_type user.Person}
or so, while now the printing works correctlyThank you so much, it works now! I overlooked the :type metadata from sci and only tried to re-add the :sci.impl/record true
. I think :type
is one of the most common keywords in metadata. Either __sci_type
, or just an ns qualified keyword would be less prone to conflict with other sort of "types".
@U014XH9MK55 Excellent!
I was going to open an issue, but in the meantime I found a comment from you that implies that metadata on SciRecord is obsolete anyway. https://github.com/babashka/sci/blob/246c6c0639d2b55082e06f03611830b99d6286ef/src/sci/impl/records.cljc#L114 Is this an ongoing change or you still prefer to have an issue about this?
@U014XH9MK55 That change wasn't made yet, but if you create an issue (perhaps in SCI) then we have more reason to work on that :)
Thank you too! I have another issue with this lib and I spent a few hours to understand what's going on. Right now I'm just shooting in the dark.
it requires to implement the implement the IFn invoke function on the record. Something like this:
(import [clojure.lang IFn])
(defrecord Person [name]
IFn
(invoke [this] (str name)))
Unfortunately adding a Java interface to a SCI record isn't yet possible. You should be hitting this: https://github.com/babashka/sci/blob/246c6c0639d2b55082e06f03611830b99d6286ef/src/sci/impl/records.cljc#L71 but it was commented out, that was an error on my part
they wrap clojure spec into a record and implement IFn on that. for example
(def my-integer? (st/spec integer?))
(my-integer? 1) => true
This coercion library also works with bb: https://github.com/exoscale/coax
bb CI runs tests for a ton of libraries that we are supporting once they work with bb
I found a bug in babashka/spec.alpha but can't open issue on that repo, where should I send it?
@U04V15CAJ , I think I need your help again, I can't wrap my head around how how symbol resolution works in bb/sci
(clojure.core/resolve 'fn)
should resolve #'clojure.core/fn
, but I get nil
. On the other hand, (clojure.core/resolve 'get)
works as expected.
to be honest, I'm not sure. it fails some unit tests, but I don't think it has a big impact in real life use cases
(st/spec (fn [x] (> x 10)))
=> #Spec{:form (clojure.core/fn [x] (clojure.core/> x 10)), :type nil, :leaf? true}
this is already an edge case when you construct a spec-tools/spec directly from a predicate and not from predefined spec
so when you create a spec it stores this predicate in the spec record. it is used directly by describe
that tells you what are the underlying predicates
it's also different from clojure.spec.alpha, where there is no resolution either (clojure.spec.alpha/describe (clojure.spec.alpha/spec (fn [] true))) => (fn [] true)
but I need to dig deeper to see if it has any impact on the logic or just extra information for the end user
I'm sorry, it was a bad example. describe trims the namespace part of the var away. describe*
keeps the resolved vars, this should give two different results between bb and clj.
(s/describe* (spec-tools.core/spec (fn [x] (> x 10))))
I removed the spec-tools
one and just used spec:
$ bb -cp src/main/clojure -e "(require '[clojure.spec.alpha :as s]) (s/describe* (s/spec (fn [x] (> x 10))))"
(clojure.core/fn [x] (clojure.core/> x 10))
which gives the same output in clj
. Do I understand that this is only an issue with bb and spec-tools
and not with bb
and clojure.spec.alpha
?Nonetheless, we could fix that. I just need to know what exactly spec-tools
is doing with the resolved var
but the whole purpose of describe and form is to give the spec predicate back to the user in data form
yes, but what I'm asking is, how does spec-tools use, in a technical sense, not in a conceptual sense, the var.
in case of fn, it checks, if the resolved value is a var (yes) and then it converts it to the clojure.core/fn
symbol
https://github.com/metosin/spec-tools/blob/master/src/spec_tools/impl.cljc#L100
furthermore the strip-fn-if-needed
relies on the qualified namespace version and won't work with just 'fn https://github.com/metosin/spec-tools/blob/master/src/spec_tools/impl.cljc#L113-L119
also unfn works explicitly with 'clojure.core/fn, but only on the sym level https://github.com/metosin/spec-tools/blob/master/src/spec_tools/impl.cljc#L42-L48
@U04V15CAJ, I came across a minor anomaly when I was debugging in bb repl. I'm not even sure if this is considered to be unexpected, so I'm curious your take on this first
if I connect to a bb nrepl server, create a record, define defmethod print-method
on the record and send the symbol to the repl, then the record base data will be printed to the repl and not the one defined in the print-method
Ah, that probably is already fixed on master. Try with:
bash <(curl ) --version 0.8.3-SNAPSHOT --dir .
if you want to try: https://gist.github.com/mathesz/28c378ec3045f74adf94ebb1396ca74e#file-bb_spec_tools_examples-clj
Are you going to try to submit this commit back to Metosin? cc @U055NJ5CC
I couldn't run the cljs tests properly, it depends on phantomjs and I'm not familiar with the setup (yet)