babashka 2020-10-21

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.

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 😛

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

@clojurians-slack100 has joined the channel

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]

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

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

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

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

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

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.

currently that's not configurable

unless you print yourself and return nil

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

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

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*)'

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

bb ... | puget --cprint

and then create an alias for it in your shell

Interesting. I'll try that, thanks!

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

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

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

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

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

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

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

and yea, puget does work for me on the JVM

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

and which shell, cmd.exe or powershell?

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?

Ah nice. It does seem to work.

sweet, yea just saw it

Also works in cmd.exe

yea, I just tested that too

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

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?

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

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

Nice! Yea, makes sense

it seems to increase binary size with 1 MB

Nice, I will use this

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

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

or use -e '(range 5)'

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>

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

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

I see it working now, sorry

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

😎 1

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

But the general idea is good!

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

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 😅

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

No thoughts on that, never used it

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

How does it compare to nippy?

I mean, why would one choose CBOR over nippy?

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

transit+messagepack?

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

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

PR welcome :)

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.

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). 🤷‍♂️

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

it seems clojure is missing?

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

(on that page)

it’s just sorted poorly

or.. not sorted? 🤷‍♂️

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

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

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

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.

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

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

yeah, I’ve only ever seen it in Jackson

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 facepalm

@borkdude nice, got it working!