Fork me on GitHub

hi, I raised an issue in babashka.fs


@eugen.stan As an alternative you can use for now

👍 1
Martynas M10:03:20

Hey. Does babashka support plumatic/schema and their generators? What about this? 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: + clojure.test.check generators

Martynas M10:03:42

Then this means that can't be supported either because it uses schema underneath. Thanks.


If these deftypes were defrecords it might work in bb though: 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.?


OK... thanks let me try that with tasks, it didn't quite click before


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


and write a small bash wrapper for that


OK, yeah, the second one feels more right to me. Considering this for example with tasks: 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.


The second one seems reasonable, let me try it.


... but ... hmm, how do I pass in input ?

bb -cp ~/tasks -m foo/bar


forget about *input* , just use (slurp *in*) in scripts.


Let me try this a while and come back.


Namespace used in foo.clj must be exactly "foo" for this to work?


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)

👍 1

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 suspected as much! Thanks anyway, I’ll suffer without it for now 😊


I do have a CLI here which brings specter to the command line:

👀 1

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


cool 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]}


I'm surprised it works :)

🤓 1
babashka 1
borkdude 1
👍 1

@odd.andreas specter is now available as a library to be used in babashka, see Changelogs :)

🙌 1
🎉 1
babashka 1

You need to use my fork though, which adds a compatibility commit for babashka. Hopefully #specter will accept it back as a PR


All specter tests are passing