Fork me on GitHub
#babashka
<
2020-09-20
>
borkdude07:09:25

@rickmoynihan Awesome. PRs welcome

👌 3
borkdude09:09:33

@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.

rickmoynihan07:09:10

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.

borkdude07:09:21

Why does integrant need spec though?

rickmoynihan07:09:16

It has a phase of initialisation called ig/pre-init-spec where you can hook specs in to validate a components config

rickmoynihan07:09:14

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.

rickmoynihan07:09:37

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.

borkdude09:09:37

> though it would be nice to run the test suites for dependency and integrant under the bb environment bb also supports clojure.test

rickmoynihan07:09:39

: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

rickmoynihan08:09:24

Where is borkdude.deps-test defined? I get the following error:

rickmoynihan08:09:35

ah I think that’s my project…

borkdude08:09:11

deps-test is just an example

👍 3
rickmoynihan08:09:12

Yeah it is — please ignore

rickmoynihan08:09:29

I clearly need more coffee — eyes glazing over 😳

borkdude08:09:08

no problem :)

borkdude09:09:58

I would also be happy to run your projects under the smoke tests that are running with bb in CI

borkdude09:09:06

(see script/run_lib_tests)

borkdude10:09:36

@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_builds

🎉 3
rickmoynihan08:09:32

Ok I think there’s a bug/limitation with constructor support

rickmoynihan08:09:00

If the constructor call occurs inside the defrecord definition it doesn’t work

rickmoynihan08:09:11

(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)))

borkdude08:09:55

ah makes sense. I'll make an issue in sci

👍 3
rickmoynihan08:09:54

Minimal example here:

rickmoynihan08:09:56

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=>

borkdude08:09:29

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=>

borkdude08:09:49

I think the second example should read something with defrecord maybe?

rickmoynihan08:09:14

Yeah sorry I pasted you the wrong bit :thumbsup:

rickmoynihan08:09:36

(defrecord Bar [] Foo (Bar.))
: Could not resolve symbol: user/Bar.

borkdude08:09:42

Luckily this does work for now:

(defrecord Foo [x] IFoo (foo [this] (->Foo x)))

rickmoynihan08:09:43

Thanks :thumbsup:

borkdude10:09:48

I hope to make a new release somewhere end of this week

borkdude21:09:36

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  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 
$ bb -Dbabashka.httpkit-server.warning=false -e "(require '[org.httpkit.server :as srv]) (srv/run-server (fn [_] {:body \"Hello\"}) {:port 8088}) @(promise)"