@rickmoynihan Awesome. PRs welcome
@rickmoynihan I made the following issue related to your attempt to make these libraries work with bb: - https://github.com/borkdude/sci/issues/418 (support invoking constructor on records) Also I included the exception type in bb master now. Regarding spec: Please leave a message here https://github.com/borkdude/babashka/issues/558 if you think spec proper should be included in bb.
Yeah Iād seen this issue, but I donāt feel qualified to contribute to the discussion at this stage.
Presumably including spec1 will bloat the binary somewhat, and itāll be hard to remove. How many libs can you statically link and maintain in the bb binary?
FWIW the spartan.spec hack seemed sufficient (putting a :bb
conditional over the require in integrant) for getting integrant to work.
Why does integrant need spec though?
It has a phase of initialisation called ig/pre-init-spec
where you can hook specs in to validate a components config
ah
Strictly speaking though I agree it could have that phase but not depend on spec.
It really only depends on it so it can raise an error with an s/explain
message that includes the name of the component that failed the spec.
I guess it could in theory be made pluggable in this regardā¦ Though that might mean some systems end up needing a combination of spec and another validation lib; as itād make each component specify itās validator; rather than having a single standard one for all systems.
> though it would be nice to run the test suites for dependency and integrant under the bb environment bb also supports clojure.test
:thumbsup: Yeah Iād seen this, I just hadnāt got around to running the projects test suites with your test runner snippet. https://github.com/borkdude/babashka#running-tests
Where is borkdude.deps-test
defined?
I get the following error:
ah I think thatās my projectā¦
deps-test is just an example
Yeah it is ā please ignore
I clearly need more coffee ā eyes glazing over š³
no problem :)
I would also be happy to run your projects under the smoke tests that are running with bb in CI
(see script/run_lib_tests)
@rickmoynihan lol, the record constructor already works with bb master:
user=> (defrecord Foo [x])
#'user/Foo
user=> (Foo. 1)
{:x 1}
user=> (ns bar)
nil
bar=> (import user.Foo)
nil
bar=> (Foo. 1)
{:x 1}
Just not released yet. Try with latest binary from master in #babashka_circleci_buildsOk I think thereās a bug/limitation with constructor support
If the constructor call occurs inside the defrecord definition it doesnāt work
e.g.
(defrecord MapDependencyGraph [dependencies dependents]
DependencyGraph
(immediate-dependencies [graph node]
(get dependencies node #{}))
(immediate-dependents [graph node]
(get dependents node #{}))
(transitive-dependencies [graph node]
(transitive dependencies #{node}))
(transitive-dependencies-set [graph node-set]
(transitive dependencies node-set))
(transitive-dependents [graph node]
(transitive dependents #{node}))
(transitive-dependents-set [graph node-set]
(transitive dependents node-set))
(nodes [graph]
(clojure.set/union (set (keys dependencies))
(set (keys dependents))))
DependencyGraphUpdate
(depend [graph node dep]
(when (or (= node dep) (depends? graph dep node))
(throw (ex-info (str "Circular dependency between "
(pr-str node) " and " (pr-str dep))
{:reason ::circular-dependency
:node node
:dependency dep})))
(MapDependencyGraph.
(update-in dependencies [node] set-conj dep)
(update-in dependents [dep] set-conj node)))
(remove-edge [graph node dep]
(MapDependencyGraph.
(update-in dependencies [node] disj dep)
(update-in dependents [dep] disj node)))
(remove-all [graph node]
(MapDependencyGraph.
(remove-from-map dependencies node)
(remove-from-map dependents node)))
(remove-node [graph node]
(MapDependencyGraph.
(dissoc dependencies node)
dependents)))
ah makes sense. I'll make an issue in sci
Minimal example here:
user=> (defprotocol Foo (foo [a]))
{:ns #object[sci.impl.vars.SciNamespace 0x70ea4d21 "user"], :methods #{#object[clojure.lang.MultiFn 0x16f3c5e "clojure.lang.MultiFn@109ab8718"]}}
user=> (defprotocol Foo (foo [a]))
: Could not resolve symbol: user=>
user=> {:ns #object[sci.impl.vars.SciNamespace 0x70ea4d21 "user"], :methods #{#object[clojure.lang.MultiFn 0x16f3c5e "clojure.lang.MultiFn@109ab8718"]}}
user=>
borkdude@MBP2019 ~ $ clj
Clojure 1.10.1
user=> (defprotocol IFoo (foo [this]))
IFoo
user=> (defrecord Foo [x] IFoo (foo [this] (Foo. x)))
user.Foo
user=> ^D
borkdude@MBP2019 ~ $ rlwrap bb
Babashka v0.2.1-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (defprotocol IFoo (foo [this]))
{:ns #object[sci.impl.vars.SciNamespace 0x3b233ecd "user"], :methods #{#object[clojure.lang.MultiFn 0x75d2c228 "clojure.lang.MultiFn@108b423c8"]}}
user=> (defrecord Foo [x] IFoo (foo [this] (Foo. x)))
: Unable to resolve classname: Foo
user=>
I think the second example should read something with defrecord maybe?
Yeah sorry I pasted you the wrong bit :thumbsup:
(defrecord Bar [] Foo (Bar.))
: Could not resolve symbol: user/Bar.
nice. Pasted the issue here: https://github.com/borkdude/sci/issues/419
Luckily this does work for now:
(defrecord Foo [x] IFoo (foo [this] (->Foo x)))
Thanks :thumbsup:
I hope to make a new release somewhere end of this week
On master:
$ bb -e "(require '[org.httpkit.server :as srv]) (srv/run-server (fn [_] {:body \"Hello\"}) {:port 8088}) @(promise)"
WARNING: the org.httpkit.server namespace is experimental and may be removed in future versions of babashka.
Please leave a note at <https://github.com/borkdude/babashka/issues/556> to let us know how you are using it.
You can turn this warning off using -Dbabashka.httpkit-server.warning=false
This namespace will remain available under a feature flag, see <https://github.com/borkdude/babashka/blob/master/doc/build.md#feature-flags>
$ bb -Dbabashka.httpkit-server.warning=false -e "(require '[org.httpkit.server :as srv]) (srv/run-server (fn [_] {:body \"Hello\"}) {:port 8088}) @(promise)"