Fork me on GitHub
#babashka
<
2020-02-17
>
sogaiu07:02:59

is there currently a good way to do piping between processes in bb (since conch is gone)? if not, does the following look interesting? or perhaps there is a way to use it as an external lib?

borkdude09:02:19

@sogaiu clojure.java.shell/sh accepts an :in argument. conch was just a layer over processbuilder, which is in bb. I'm using this directly in e.g. deps.clj: https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L16-L52

sogaiu09:02:15

thanks for the pointer!

Mno09:02:54

https://github.com/lambdaisland/regal looks cool, might be nice for babashka since is it also helps make regex be a bit more readable.. but it's also kind of redundant since core.re-matches and core.re-find are there

borkdude09:02:58

Maybe it works as an external lib:

$ export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {regal
                       {:git/url "" :sha "e179f20a2ec78d47c8c24257e644ac80a70e33cb"}}}')
 $ bb "(require '[lambdaisland.regal :as re]) (re/regex [:range \a \z])"
I don't see any weird errors, but also not a regex result.

borkdude09:02:06

oh I see! it's because it uses reader conditionals and there is no :bb reader conditional

borkdude09:02:15

so it just returns nil for some functions

Mno09:02:06

awww that's unfortunate, maybe I can convince them to get some bb conditionals, or just fork it.

borkdude09:02:43

already done, read ahead 😃

Mno09:02:47

oh.. I really should read more and talk less xD

jeroenvandijk09:02:48

Did you consider to have a mode where babashka would use the :clj reader conditional tag? In many cases that will work I'm guessing. I think that's what I saw in one of the patches with :bb reader conditionals

borkdude09:02:04

$ export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {regal {:git/url "" :sha "42906e57bf45e9d6cb699700ea19e653757f535d"}}}')
$ bb "(require '[lambdaisland.regal :as re]) (re/regex [:range \a \z])"
#"[a-z]"

borkdude09:02:10

@jeroenvandijk I think that makes sense. Maybe if the :bb branch appears before the :clj branch, it will take that one, else it will take the :clj branch?

jeroenvandijk09:02:36

Yeah so the only case where it could go wrong is where the writer intentionally left :bb out (i.e. meaning no implementation. Right now this seems like a rare case. When it's intentionally left blank we could also demand :bb nil as that would make it explicitly and unambiguous. So for all the cases where :clj is compatible (and no :bb is needed) it would just work

borkdude09:02:33

this would only take a minor change in bb, most notably here:

src/babashka/main.clj
330:                 :features #{:bb}

borkdude09:02:04

still forking libs might be a good idea because the original author is not always willing to maintain compatibility with bb maybe

jeroenvandijk09:02:13

Yeah that's actually a good practise in general, also for :clj

borkdude09:02:09

what is the good practice you're referring to, forking?

jeroenvandijk10:02:37

yeah, forking sorry. I don't always do it, but it's a pity when your favourite library has been removed from one day to the other and you didn't fork it

Mno12:02:34

maybe making it explicit in the import instead? like

$ export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {regal {:git/url "" :sha "42906e57bf45e9d6cb699700ea19e653757f535d" :reader/tag :clj}}}')

borkdude13:02:22

that command just produces a classpath using the clojure tool, which just ignores extra stuff you put inside -Sdeps

Mno13:02:39

ah dangit

borkdude13:02:28

but bb could be configurable like --features bb,clj or something, but that might work out very confusing if some libraries do expect a bb tag and others don't. I think it might be better to just have one kind of behavior for everything

Mno13:02:43

yeah makes sense.

borkdude13:02:13

it would be a breaking change, but since the amount of bb-compatible libs in the wild might not be that large yet, it may be a good time to do it now

Mno13:02:09

I mean the ones it has seems to cover the vast majority of the "bash script" domain

Mno15:02:59

I think I may have found a bug, would you rather I make a small issue with example or just say it here? (it seems the alias for tools.cli is not working? (clojure.tools.cli/parse-opts *command-line-args* cli-options) works but (tools.cli/parse-opts *command-line-args* cli-options) doesn't (java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn)

borkdude15:02:43

lemme check

borkdude15:02:25

I see the bug:

(def aliases
  '{tools.cli 'clojure.tools.cli
    edn clojure.edn
    wait babashka.wait
    signal babashka.signal
    shell clojure.java.shell
    io 
    async clojure.core.async
    csv clojure.data.csv
    json cheshire.core})

borkdude15:02:38

there's a quote too many. PR welcome!

borkdude15:02:09

for now you can also do (require '[clojure.tools.cli :as foo])

Mno15:02:35

I did that yeah

Mno20:02:17

Yay! awesome!