Fork me on GitHub
#babashka
<
2020-01-31
>
Crispin07:01:03

Awesome work on the multimethod support!

borkdude08:01:34

thanks 🙂

borkdude10:01:27

My Github sponsors profile finally went live. If you're using babashka and/or sci and want to show your support, here's a way. Even if only for 1 dollar a month, it helps sustain these projects. https://github.com/sponsors/borkdude

💰 8
borkdude11:01:10

That's right, now I will become rich! Of course babashka / sci remains free and I will love you just as much even if you don't become a sponsor ❤️

jeroenvandijk10:01:44

I've modified an older example using a forked version of Mori.js

jeroenvandijk10:01:56

I have done it before with self-hosted Clojurescript which was hacky to get working. I think the interop features of Sci could make this quite interesting. Hopefully someone picks it up:)

borkdude10:01:24

where do you specify the dependency on sci?

borkdude10:01:21

or does require automatically pick the newest version from npm?

jeroenvandijk10:01:35

They proxy npm somehow

jeroenvandijk10:01:35

You can probably also specify versions. I played with it a longer time ago and don't remember. I was lucky enough to get my old example working with Sci in a few minutes 😎

borkdude10:01:51

pretty cool 🙂

jeroenvandijk10:01:01

I think so too!

jeroenvandijk11:01:07

And what's cooler than self-hosted clojurescript is that

cljs `(fn [a b] (+ a b))` 
Returns an actual javascript function that can be used with arbitrary JS results. I hope to think of a usecase soon 🙂

jeroenvandijk11:01:27

some js -> sci interop in action

🕶️ 4
stijn13:01:24

@borkdude first, thanks for creating babashka it's pretty awesome :)

stijn13:01:45

i have a question about the usage with deps.edn. how can I pass on additional arguments? The following works in Clojure for JVM

clj -A:main -e some-option some-action
I've tried various positions of -e some-option some-action at
deps.exe -A:main -Scommand "bb -cp {{classpath}} {{main-opts}}"
but, I can't get it to work

stijn13:01:35

okay, the new -- option that I read about in #tools-deps works!

stijn13:01:05

deps.exe -A:main -Scommand "bb -cp {{classpath}} {{main-opts}}" -- -e some-option some-action

borkdude13:01:17

even without -- the above example should work I think

borkdude13:01:56

but great to hear that also worked for you and thanks for the compliment

stijn14:01:45

actually i'm still not able to get it to work

stijn14:01:10

❯ deps.exe -A:main -e foo bar                                                        
(-e foo bar)
= correct
❯ deps.exe -A:main -Scommand "bb -cp {{classpath}} {{main-opts}}" -e foo bar         
clojure.lang.ExceptionInfo: Could not resolve symbol: foo [at line 1, column 1]

stijn14:01:30

the main does (println args)

stijn14:01:12

❯ deps.exe -A:main -Scommand "bb -cp {{classpath}} {{main-opts}}" -- -e foo bar
(-- -e foo bar)

borkdude14:01:39

yeah, in that case -e is passed to babashka and babashka interprets -e foo as "execute the expression foo` which is why you see that message

borkdude14:01:21

and babashka doesn't have support for -- yet, but I did want to add that

stijn14:01:09

I see, makes sense

borkdude14:01:15

so you're dealing with two levels of argument parsing here, one for deps.clj and one for babashka itself

stijn14:01:25

No worries, I can run with clj main for now. Really nice how you designed the usage of babashka with deps.edn, so you can easily switch between REPL on clojure JVM, main on JVM and babashka for running the shell scripts

stijn15:01:06

Am I correct that babashka also executes the code when it is generating an uberscript?

stijn15:01:35

(i mean, with deps.exe)

borkdude15:01:49

it shouldn't. it does run through the script for analysis, but it doesn't actually execute any functions

stijn15:01:52

or maybe it is deps.exe that is executing the code

stijn15:01:53

❯ deps.exe -M:main -Scommand "bb -cp {{classpath}} {{main-opts}} --uberscript my-script.clj"
nil

stijn15:01:20

that nil is the list of command line args that the main of my script prints out

borkdude15:01:21

does that generate a script for you?

stijn15:01:18

but if I put my real code in, it doesn't, since there are (System/exit 1) statements in there because the command line args don't match what the actual script wants

stijn16:01:26

❯ deps.exe -A:main -Scommand "bb -cp {{classpath}} {{main-opts}} --uberscript my-script.clj" this is a test
(this is a test)
with
(defn -main [& args]
  (println args))

borkdude16:01:01

ah... hmm, I see! I have an option in sci (the interpreter) called :dry-run which is what babashka uses to analyze all the code instead of executing it and then emits all the code that was loaded to the uberscript. but I only check the :dry-run option in a function call, not when doing interop... https://github.com/borkdude/sci/blob/398d15b8d940dd53fac17a263bbba35318ef5a0e/src/sci/impl/interpreter.cljc#L474

borkdude16:01:28

so a workaround for now might be to wrap System/exit in a function and that should do the trick

borkdude16:01:01

let me try with that main function

borkdude16:01:30

ah, that is executes the main function might be a regression

borkdude16:01:53

ah I see:

(cond
               (ifn? f) (fn-call ctx f (rest expr))
               (:dry-run ctx) nil
               :else
               (throw (new #?(:clj Exception :cljs js/Error)
                           (str "Cannot call " (pr-str f) " as a function."))))

borkdude16:01:00

the order is wrong there

borkdude16:01:49

I swapped it when doing optimizations. doh!

borkdude16:01:20

let me provide you with a fix for testing. do you run linux or mac?

borkdude16:01:54

@stijn I pushed a fix to master. Shortly there will be a link for a new linux binary in #babashka_circleci_builds

borkdude16:01:34

I now also added the -- option

stijn16:01:45

that works, cool!

👍 4
stijn19:01:19

confirmed that the -- works as well

deps.exe -A:main -Scommand "bb -cp {{classpath}} {{main-opts}} -- $@"
thanks @borkdude

borkdude19:01:59

thanks for testing

borkdude19:01:48

hmm @deleted-user weren't you also having issues with the uberscript? might be the same as the above?

borkdude19:01:57

don't remember when this was

borkdude19:01:11

aah same issue then

borkdude19:01:24

want to test with a new binary?

borkdude19:01:37

if so, linux or mac?

borkdude19:01:15

sure, no hurry

borkdude19:01:30

ah good, thanks

borkdude20:01:16

I'll make a new release with these fixes

borkdude21:01:20

it just has two bugfixes and one new thing, I'll append it to the previous announcement

borkdude21:01:05

@deleted-user I noticed you were using spartan.test, if you haven't read it yet, clojure.test is now built in