Fork me on GitHub
#babashka
<
2020-10-21
>
jvtrigueros01:10:52

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.

jvtrigueros01:10:41

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 šŸ˜›

borkdude19:10:12

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.

9
Santiago20:10:31

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]

borkdude20:10:48

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

borkdude20:10:05

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

Santiago20:10:17

ah I get it.. thought I had installed it with brew but didnā€™t. thanks

borkdude21:10:10

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

Santiago21:10:05

youā€™re everywhere @U04V15CAJ šŸ˜„ yeah looking at them now

isak21:10:56

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.

borkdude21:10:49

currently that's not configurable

borkdude22:10:03

unless you print yourself and return nil

isak22:10:06

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

isak22:10:41

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

borkdude11:10:42

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

borkdude11:10:14

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

borkdude11:10:18

bb ... | puget --cprint

borkdude11:10:24

and then create an alias for it in your shell

isak14:10:38

Interesting. I'll try that, thanks!

borkdude14:10:19

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

borkdude14:10:40

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

isak14:10:42

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

isak14:10:36

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

borkdude14:10:01

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

isak14:10:40

ah I see

borkdude14:10:42

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

borkdude14:10:16

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

šŸ‘€ 3
isak14:10:22

and yea, puget does work for me on the JVM

isak14:10:41

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

borkdude14:10:59

and which shell, cmd.exe or powershell?

isak14:10:39

powershell

borkdude14:10:21

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?

borkdude14:10:10

Ah nice. It does seem to work.

isak14:10:23

sweet, yea just saw it

borkdude14:10:20

Also works in cmd.exe

isak14:10:43

yea, I just tested that too

isak14:10:42

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

borkdude14:10:32

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?

borkdude14:10:10

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

borkdude14:10:53

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

isak14:10:56

Nice! Yea, makes sense

borkdude15:10:58

it seems to increase binary size with 1 MB

isak15:10:27

Nice, I will use this

isak15:10:36

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

borkdude15:10:05

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

borkdude15:10:25

or use -e '(range 5)'

isak15:10:40

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>

borkdude15:10:46

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

isak15:10:25

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

isak15:10:07

I see it working now, sorry

greglook18:10:07

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

šŸ˜Ž 3
borkdude18:10:13

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

borkdude18:10:26

But the general idea is good!

borkdude18:10:00

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

greglook18:10:11

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 šŸ˜…

greglook18:10:51

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

borkdude18:10:01

No thoughts on that, never used it

greglook18:10:38

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

borkdude18:10:35

How does it compare to nippy?

borkdude18:10:39

I mean, why would one choose CBOR over nippy?

isak18:10:51

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

borkdude18:10:49

transit+messagepack?

borkdude18:10:43

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

borkdude18:10:37

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

borkdude18:10:41

PR welcome :)

greglook20:10:53

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.

greglook20:10:09

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:

borkdude20:10:34

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

borkdude20:10:13

it seems clojure is missing?

greglook20:10:14

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

borkdude20:10:24

(on that page)

greglook20:10:32

itā€™s just sorted poorly

greglook20:10:47

or.. not sorted? :man-shrugging:

borkdude20:10:20

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

greglook20:10:32

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

greglook20:10:57

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

greglook20:10:30

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.

borkdude21:10:22

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

borkdude21:10:03

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

greglook21:10:30

yeah, Iā€™ve only ever seen it in Jackson

greglook21:10:47

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

isak14:10:14

@U04V15CAJ nice, got it working!