This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-08
Channels
- # aleph (2)
- # announcements (2)
- # asami (50)
- # babashka (39)
- # beginners (17)
- # calva (61)
- # cider (9)
- # clj-kondo (5)
- # clojure (37)
- # clojure-europe (52)
- # clojure-nl (1)
- # clojure-norway (14)
- # clojure-uk (5)
- # clojurescript (28)
- # cursive (3)
- # datahike (11)
- # datomic (28)
- # deps-new (11)
- # events (3)
- # fulcro (18)
- # google-cloud (1)
- # graphql (8)
- # introduce-yourself (4)
- # jobs (2)
- # leiningen (7)
- # lsp (15)
- # pathom (9)
- # re-frame (6)
- # reagent (35)
- # reitit (17)
- # releases (1)
- # shadow-cljs (20)
- # specter (1)
- # test-check (106)
- # tools-deps (8)
- # uncomplicate (1)
- # vim (29)
hi, I raised an issue in babashka.fs https://github.com/babashka/fs/issues/48
Hey. Does babashka support plumatic/schema
and their generators?
What about this? https://github.com/deercreeklabs/lancaster
Is there a good reason it should support some of this?
@invertisment_clojuria It does not support schema (I doubt it will work from source), but bb does support clojure.spec.alpha (from source, here: https://github.com/babashka/spec.alpha) + clojure.test.check generators
Then this means that
can't be supported either because it uses schema underneath. Thanks.
If these deftype
s were defrecords
it might work in bb though:
https://github.com/plumatic/schema/blob/2b864ab32ddf48bebe779876506577838a32dd1b/src/cljc/schema/utils.cljc#L91
It's worth looking into this.
I'm struggling to organize my babashka project in a way that feels convenient with bb.edn vs preload vs tasks vs bb-invocation flags etc. My goal is simply to replace several bash aliases and shell functions with clojure implementations. Would anyone like to help me with tips/best practice/etc?... More details coming in thread.
Basically, what I expect is this and I might extend it from there
1. One CLJ file containing several independent functions
2. Possibly using some extra Java lib, if it loads fast enough
3. Likely using some clojure libs
4. One .sh file connecting them, e.g.
alias doit='bb -i '(myutils/doit *input*)'
doit2() { # shell function
some shell code
branch out to clojure
}
Now, I looked at tasks but I'm not sure if I get it, or if it doesn't apply. It seems to suggest it should replace "Makefile" style operations. So it is for building/doing stuff with your project, rather than implementing small callable functions like above? Or is tasks the right way to access the individual functions in a single utils.clj ? It just hasn't clicked for me so far.
@U0359E1F02H You can make a global tasks file in e.g. ~/tasks/bb.edn
and then call it with bb --config ~/tasks/bb.edn mytask
. You can make a small bash wrapper for this, so you can call tasks mytask
Of course I want the bb invocation to be as simple as possible from the shell side, but whatever is required is fine.... Another idea is to have a main function, which takes an argument and calls out to the clojure function with that name and provides the *command-line-args and input* etc.?
You are right that tasks are mainly for project-specific tasks, but it can be used as I described above too
What you can also do:
bb -cp ~/tasks -m foo/bar
which executes the function bar
in ~/tasks/foo.clj
OK, yeah, the second one feels more right to me. Considering this for example with tasks: https://gist.github.com/borkdude/35bc0a20bd4c112dec2c5645f67250e3 It feels to me like another indirection level. It feels more natural to me to do bb '(clojure function)' rather than bb 'task' and have to define each "task" as a simple redirect to the actual clojure function I want to call. and defining them all inside of the { } structure just doesn't feel nice to me.
Got it. Yes I think this got me over the hump. Thanks @U04V15CAJ. And thanks for BB, awesome stuff! (I already wrote many of the functions 🎉 so I'm glad I got this invocation stuff clarified)
Hello! Is there a way to require Specter in a bb-script? I’ve tried this:
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {com.rpl/specter {:mvn/version "1.1.3"}
; Add ridley because specter complains about it being missing
riddley/riddley {:mvn/version "0.1.12"}}})
(require '[com.rpl.specter :as s])
; => java.lang.Exception: Unable to resolve classname: clojure.lang.Var [at riddley/compiler.clj:2:3]
@odd.andreas specter relies on pretty low level Clojure stuff which isn't supported in bb (yet)
I do have a CLI here which brings specter to the command line: https://github.com/borkdude/specter-cli
@odd.andreas I briefly looked into it and it seems specter may work with bb if a few patches are applied:
$ clojure -M:babashka/dev -cp src/clj -e "(use '[com.rpl.specter]) (def data [1 2 3 4 5 6 7 8]) (transform [ALL] inc data)"
[2 3 4 5 6 7 8 9]
It won't be fast, but you will have the convenience of the DSLcool beans! The performance aspect isn’t that interesting to me at least, I was just working on a script that transformed a nested yaml file and the code ended up looking pretty horrible (`(update .. (map (update .. (map …))))`) So I figured if specter was easily available I could at least write a simple path down to the thing I want to modify 😊
I discovered some things which need to be fixed first so maybe in a couple of weeks or so
Very cool, thanks! Really loving Babashka as a tool so far 🙏 My use-case is covered for now with my terrible update-algorithm so I’m not in a hurry 😊
$ ./bb -cp src/clj -e "(use '[com.rpl.specter]) (def data {:a [1 2 3]}) (setval [:a END] [4 5] data)"
{:a [1 2 3 4 5]}
@odd.andreas specter is now available as a library to be used in babashka, see Changelogs :)