babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Dig 2020-10-21T01:07:52.043400Z

it works! thank you for all the hard work!

2020-10-21T01:08:52.044300Z

Hi, I'm attempting to create an uberscript, but when I execute the final file I'm getting this error:

line 1: ns: command not found
....
I'm creating this uberscript with this command BABASHKA_CLASSPATH=$(lein with-profile -dev classpath) bb -f src/demo/main.clj -m demo.main --uberscript demo.clj On the resulting demo.clj file, I see the main.clj source and appended there's another line of code added. I'm thinking that I'm using this command incorrectly, but I wasn't able to find any example.

borkdude 2020-10-21T07:48:53.045300Z

:)

2020-10-21T01:17:41.044500Z

Ok this turned out being user error. I forgot to add the #!/usr/bin/env bb to the top of the file before executing it 😛

borkdude 2020-10-21T19:42:12.046500Z

babashka v0.2.3 released! https://github.com/borkdude/babashka/blob/master/CHANGELOG.md#v023-2020-10-21 Featuring babashka/process: a new Clojure library around dealing with java.lang.Process and many other additions and fixes.

3
Santiago 2020-10-21T20:26:31.047800Z

do I need to do something else before using pods? bootleg and clj-kondo works fine

> (pods/load-pod "pod-babashka-hsqldb")
> java.io.IOException: Cannot run program "pod-babashka-hsqldb": error=2, No such file or directory [at <repl>:5:1]

borkdude 2020-10-21T20:45:48.048Z

This assumes you have pod-babashka-hsqldb on your path.

borkdude 2020-10-21T20:46:05.048200Z

@slack.jcpsantiago If used from the local dir, you need to prepend it with "./" like on the command line

Santiago 2020-10-21T20:55:17.048600Z

ah I get it.. thought I had installed it with brew but didn’t. thanks

borkdude 2020-10-21T21:20:10.048800Z

btw about the aws pod: it uses the Go SDK under the hood so maybe you can find it in their docs

Santiago 2020-10-21T21:29:05.049Z

you’re everywhere @borkdude 😄 yeah looking at them now

isak 2020-10-21T21:56:56.050300Z

Is it possible to change the default print method used by babashka? (How last form in the script is printed). For example, I'd like to try rendering it to the console with indenting + colors with puget.

borkdude 2020-10-21T21:59:49.050600Z

currently that's not configurable

borkdude 2020-10-21T22:00:03.050900Z

unless you print yourself and return nil

isak 2020-10-21T22:39:13.051300Z

Ah, ok

isak 2020-10-21T22:54:06.052400Z

Not sure if this is a good idea, but what about auto pprinting in some instances, like when connected to a terminal?

isak 2020-10-21T22:56:41.053600Z

A more conservative option would be to make the print wrapper configurable, like prn -> puget/pprint. Because then we could use preloads + that new option to make it work, I think

borkdude 2020-10-22T11:14:42.055200Z

I have enabled puget in a branch. It does work, but it breaks piping.

$ /usr/local/bin/bb '{:a (repeat 10 {:a 1 :b 2 :c 3})}' | /usr/local/bin/bb '(:a *input*)'
({:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1} {:c 3, :b 2, :a 1})
borkdude@MBP2019 ~/Dropbox/dev/clojure/babashka (puget*) $ ./bb '{:a (repeat 10 {:a 1 :b 2 :c 3})}' | ./bb '(:a *input*)'

borkdude 2020-10-22T11:16:14.055400Z

Maybe puget can be made into its own GraalVM binary so you can pipe EDN to that and colorize it at will

borkdude 2020-10-22T11:16:18.055600Z

bb ... | puget --cprint

borkdude 2020-10-22T11:25:24.056Z

and then create an alias for it in your shell

isak 2020-10-22T14:18:38.056900Z

Interesting. I'll try that, thanks!

borkdude 2020-10-22T14:24:19.057100Z

I think such a tool will be very helpful in other contexts too. Any tool outputting EDN can then be piped into that

borkdude 2020-10-22T14:27:40.057400Z

@isak There's also a zprint GraalVM binary: https://github.com/kkinnear/zprint Maybe that also supports colors?

isak 2020-10-22T14:32:42.057800Z

I looked at that one before and it seems good, but doesn't support windows builds

isak 2020-10-22T14:33:36.058Z

I was gonna try wrapping babashka with another babashka script that adds puget

borkdude 2020-10-22T14:34:01.058200Z

I don't think puget will work from source with babashka

isak 2020-10-22T14:34:40.058400Z

ah I see

borkdude 2020-10-22T14:35:42.058600Z

but puget does work for you from the JVM? which terminal are you using?

borkdude 2020-10-22T14:36:16.058800Z

the reason I'm asking is, I have a pod for making TUIs: https://github.com/babashka/pod-babashka-lanterna but it doesn't work on Windows because of the terminal differences

👀 1
isak 2020-10-22T14:36:45.059200Z

I'm using Windows Terminal: https://docs.microsoft.com/en-us/windows/terminal/

isak 2020-10-22T14:37:22.059600Z

and yea, puget does work for me on the JVM

isak 2020-10-22T14:37:41.059800Z

Though I haven't tried piping it to the console, just HTML output so far

borkdude 2020-10-22T14:37:59.060Z

and which shell, cmd.exe or powershell?

isak 2020-10-22T14:40:39.060200Z

powershell

borkdude 2020-10-22T14:41:21.060400Z

I made a babashka puget branch. Can you maybe test it by running lein bb '{:a (repeat 10 {:a 1 :b 2 :c 3})}' and then see what it prints?

borkdude 2020-10-22T14:41:25.060600Z

in PS

isak 2020-10-22T14:42:26.061300Z

yea

borkdude 2020-10-22T14:44:10.061500Z

Ah nice. It does seem to work.

borkdude 2020-10-22T14:44:20.061700Z

isak 2020-10-22T14:44:23.062100Z

sweet, yea just saw it

borkdude 2020-10-22T14:45:20.062300Z

Also works in cmd.exe

isak 2020-10-22T14:45:43.062500Z

yea, I just tested that too

isak 2020-10-22T14:46:42.062700Z

What if pugetting the output was a switch? Similar to how you have the -O

borkdude 2020-10-22T14:55:32.063Z

I pushed a commit with --puget. We might want to generalize this to --print-fn which defaults to clojure.core/prn but can be set to clojure.pprint/pprint or puget/cprint or whatever maybe?

borkdude 2020-10-22T14:56:10.063200Z

I want to pay attention to the increase in compilation memory usage and binary size first before deciding on this

borkdude 2020-10-22T14:56:53.063400Z

splitting it into its own binary has the benefit of wider utility perhaps

borkdude 2020-10-22T14:58:33.063600Z

Also made these issues for it: - https://github.com/borkdude/babashka/issues/620 - https://github.com/greglook/puget/issues/53

isak 2020-10-22T14:59:56.064200Z

Nice! Yea, makes sense

borkdude 2020-10-22T15:04:22.064400Z

@isak it's done building here: https://ci.appveyor.com/project/borkdude/babashka

borkdude 2020-10-22T15:04:58.064600Z

it seems to increase binary size with 1 MB

isak 2020-10-22T15:05:27.064800Z

Nice, I will use this

isak 2020-10-22T15:12:36.065100Z

Hmm I get a problem:

PS C:\Users\isak.sky> bb '(range 5)'
(0 1 2 3 4)
PS C:\Users\isak.sky> bb --puget '(range 5)'
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  File does not exist: --puget

borkdude 2020-10-22T15:13:05.065300Z

put --puget as the last option. I implemented it so that --puget can get an optional option

isak 2020-10-22T15:13:15.065600Z

ah ok

borkdude 2020-10-22T15:13:25.065800Z

or use -e '(range 5)'

isak 2020-10-22T15:15:40.066Z

Ok now I don't get an error, but no colors/formatting:

PS C:\Users\isak.sky> bb -e '(into {:foo :bar} (for [i (range 10)] [i i]))' --puget
{0 0, 7 7, 1 1, 4 4, 6 6, 3 3, :foo :bar, 2 2, 9 9, 5 5, 8 8}
PS C:\Users\isak.sky> bb -e '(into {:foo :bar} (for [i (range 10)] [i i]))' --puget $true
{0 0, 7 7, 1 1, 4 4, 6 6, 3 3, :foo :bar, 2 2, 9 9, 5 5, 8 8}
PS C:\Users\isak.sky>

borkdude 2020-10-22T15:17:46.066200Z

Are you sure you're using the right version. Doesn't look like it

isak 2020-10-22T15:19:25.066400Z

ah it is the old one now, strange - i checked this before

isak 2020-10-22T15:21:07.066600Z

I see it working now, sorry

greglook 2020-10-22T18:29:07.068200Z

I did make https://github.com/greglook/edn-tool as a standalone tool a couple years ago, in any case. 😄

😎 1
borkdude 2020-10-22T18:32:13.068500Z

@greg316 Nice. I just tried it. But I think the name should change to puget or pprint or something more akin to prettifying EDN

borkdude 2020-10-22T18:32:26.068700Z

But the general idea is good!

borkdude 2020-10-22T18:33:00.068900Z

I guess the only thing missing is a Windows release, which graalvm now supports

greglook 2020-10-22T18:35:11.069100Z

yeah it was going to be more general-purpose and support querying and transformation and such, but then https://github.com/borkdude/jet did all that 😅

greglook 2020-10-22T18:35:51.069600Z

semi related, thoughts on supporting CBOR in jet? https://github.com/greglook/clj-cbor

borkdude 2020-10-22T18:37:01.069900Z

No thoughts on that, never used it

greglook 2020-10-22T18:38:38.070100Z

I might tackle it one of these days - CBOR is great, it’s basically binary EDN

borkdude 2020-10-22T18:40:35.070300Z

How does it compare to nippy?

borkdude 2020-10-22T18:41:39.070500Z

I mean, why would one choose CBOR over nippy?

isak 2020-10-22T18:42:51.070700Z

Nippy is not standardized, maybe that is why. (So you're unlikely to get implementations in other languages)

borkdude 2020-10-22T18:43:32.070900Z

good point

borkdude 2020-10-22T18:43:49.071100Z

transit+messagepack?

borkdude 2020-10-22T18:47:43.071300Z

anyway to get back on point, I think a puget tool that only focuses on pprinting might be nice. I'm not sure if that fits with jet since it should then also colorize json output etc

borkdude 2020-10-22T18:50:37.071500Z

adding cbor and nippy to jet, I think that can work

borkdude 2020-10-22T18:50:41.071700Z

PR welcome :)

greglook 2020-10-22T20:25:53.072200Z

Nippy is... It’s fast, but it’s not a standard so it’s clojure-only (including non-cljs). It does naive fallback to Java Serializable, so if you don’t define a custom formatter for some type like org.joda.time.DateTime it will blow up to hundreds of bytes when serialized. We also observed backwards-incompatible minor version changes, which broke all of our stored data. 😬 I would not recommend it.

greglook 2020-10-22T20:28:09.072400Z

I also like CBOR over transit+msgpack because it’s a lot simpler as a format and implementation, supports a wider variety of types, and is similarly more widely-supported (since transit is also clojure-specific). :man-shrugging:

borkdude 2020-10-22T20:43:34.072600Z

@greg316 sounds interesting. if CBOR is widely supported, maybe it's also a good candidate to add to pods as a wire format

greglook 2020-10-22T20:44:21.072800Z

pretty wide: http://cbor.io/impls.html

borkdude 2020-10-22T20:45:13.073Z

it seems clojure is missing?

greglook 2020-10-22T20:45:14.073200Z

one of the explicit goals of the RFC is a simple/compact implementation in addition to compact message representation 😁 - so it’s pretty easy to write a codec

borkdude 2020-10-22T20:45:24.073400Z

(on that page)

greglook 2020-10-22T20:45:32.073600Z

it’s just sorted poorly

borkdude 2020-10-22T20:45:45.073800Z

oh right

greglook 2020-10-22T20:45:47.074Z

or.. not sorted? :man-shrugging:

borkdude 2020-10-22T20:55:20.074200Z

@greg316 So if you decided to support a custom format, say a Clojure set, then I guess there is no standard way of decoding that in, say Go, right?

greglook 2020-10-22T20:56:32.074400Z

it’s a lot like EDN’s tagged literals; there is an IANA registry entry for “sets”, which are represented as an array of elements with tag 258

greglook 2020-10-22T20:56:57.074600Z

obviously in clojure those turn into #{} but it’d be up to golang to decide what type to represent sets with - I’m guessing there’s similarly some native language type for them

greglook 2020-10-22T20:57:05.074800Z

https://github.com/greglook/clj-cbor#type-extensions

greglook 2020-10-22T20:59:30.075400Z

The types most likely to be “weird” in other languages are keywords and symbols, which are ubiquitous in clojure but likely don’t have as direct a representation in other languages. You could define a handler for those tags to stringify them for a simple lossy conversion though, which is probably fine for things like map keys.

borkdude 2020-10-22T21:01:49.075600Z

then there's also https://github.com/FasterXML/smile-format-specification

borkdude 2020-10-22T21:02:22.076200Z

(bb already supports this since it has cheshire built-in)

borkdude 2020-10-22T21:12:03.076400Z

It seems that smile isn't that well supported outside of Java

greglook 2020-10-22T21:55:30.076600Z

yeah, I’ve only ever seen it in Jackson

greglook 2020-10-22T21:56:47.076800Z

a lot of these binary formats (smile, msgpack, jsonb, etc) all fell into the same trap of, “like JSON, but binary!” without solving the type extension problem 🤦

borkdude 2020-10-23T14:47:09.077900Z

@isak @greg316 Made this now: https://github.com/borkdude/puget-cli

isak 2020-10-23T14:55:14.078600Z

@borkdude nice, got it working!