babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
rafaeldelboni 2021-06-18T12:57:59.104300Z

Hey Borkdude I just rewrote my https://github.com/rafaeldelboni/dotfiles/tree/master/config/i3blocks/scripts using babashka instead of bash and is incredible, thanks a lot for all your work and enabling us to move out the ugly bashscripts 😄

borkdude 2021-06-18T12:58:46.104600Z

🎉 thanks for sharing :)

littleli 2021-06-18T13:24:20.104800Z

damn, this is cool 🙂

borkdude 2021-06-18T13:27:48.105Z

Btw, feel free to post it here: https://github.com/babashka/babashka/discussions/categories/show-and-tell I think the Github Discussions board can be a nice place to share this stuff as well.

borkdude 2021-06-18T13:28:00.105400Z

Did anything cool with babashka? Consider sharing it here: https://github.com/babashka/babashka/discussions/categories/show-and-tell

rafaeldelboni 2021-06-18T13:30:11.105500Z

Ah ok I will, thanks

dabrazhe 2021-06-18T17:36:51.108300Z

I'm a getting a stack trace as the result of a function chain, but no idea in where / which function it has occurred. Is there a way to improve it ?

#error {
 :cause nil
 :via
 [{:type java.lang.NullPointerException
   :message nil
   :at [clojure.lang.Numbers ops Numbers.java 1068]}]
 :trace
 [[clojure.lang.Numbers ops Numbers.java 1068]
  [clojure.lang.Numbers isZero Numbers.java 117]
  [clojure.core$zero_QMARK_ invokeStatic core.clj 874]
  [clojure.core$zero_QMARK_ invoke core.clj 869]
  [sci.impl.analyzer$return_call$fn__18447 invoke analyzer.cljc 811]  etc...

borkdude 2021-06-18T17:37:41.109Z

@dennisa when you invoke the script from the command line you will likely get a better error message

borkdude 2021-06-18T17:37:54.109300Z

also the exception should probably have a line and column number

borkdude 2021-06-18T17:37:57.109500Z

and file name

dabrazhe 2021-06-18T17:38:11.109800Z

in CLI, but not in the Repl?

borkdude 2021-06-18T17:38:13.109900Z

if not, repro welcome

borkdude 2021-06-18T17:38:17.110100Z

yes

borkdude 2021-06-18T17:38:35.110500Z

are you using the nREPL btw? please provide as much info as you can about your environment

dabrazhe 2021-06-18T17:39:37.110800Z

#error {
 :cause nil
 :via
 [{:type java.lang.NullPointerException
   :message nil
   :at [clojure.lang.Numbers ops Numbers.java 1068]}]
 :trace
 [[clojure.lang.Numbers ops Numbers.java 1068]
  [clojure.lang.Numbers isZero Numbers.java 117]
  [clojure.core$zero_QMARK_ invokeStatic core.clj 874]
  [clojure.core$zero_QMARK_ invoke core.clj 869]
  [sci.impl.analyzer$return_call$fn__18447 invoke analyzer.cljc 811]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.analyzer$return_if$fn__18211 invoke analyzer.cljc 462]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.evaluator$eval_let$fn__17163 invoke evaluator.cljc 68]
  [sci.impl.evaluator$eval_let invokeStatic evaluator.cljc 62]
  [sci.impl.analyzer$expand_let_STAR_$fn__18173 invoke analyzer.cljc 338]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.evaluator$eval_try invokeStatic evaluat
or.cljc 133]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 403]
  [sci.impl.analyzer$return_do$fn__17612 invoke analyzer.cljc 117]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.fns$fun$arity_4__16544 invoke fns.cljc 149]
  [sci.impl.vars.SciVar invoke vars.cljc 321]
  [sci.impl.analyzer$return_call$fn__18453 invoke analyzer.cljc 811]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.evaluator$eval_let$fn__17163 invoke evaluator.cljc 68]
  [sci.impl.evaluator$eval_let invokeStatic evaluator.cljc 62]
  [sci.impl.analyzer$expand_let_STAR_$fn__18173 invoke analyzer.cljc 338]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.evaluator$eval invoke evaluator.cljc 385]
  [sci.impl.fns$fun$arity_2__16520 invoke fns.cljc 141]
  [sci.impl.vars.SciVar invoke vars.cljc 317]
  [sci.impl.analyzer$return_call$fn__18449 invoke analyzer.cljc 8
11]
  [sci.impl.evaluator$eval invokeStatic evaluator.cljc 390]
  [sci.impl.interpreter$eval_form invokeStatic interpreter.cljc 77]
  [sci.core$eval_form invokeStatic core.cljc 257]
  [babashka.nrepl.impl.server$eval_msg$fn__30614 invoke server.clj 44]
  [babashka.nrepl.impl.server$eval_msg invokeStatic server.clj 32]
  [babashka.nrepl.impl.server$session_loop invokeStatic server.clj 223]
  [babashka.nrepl.impl.server$listen$fn__30688 invoke server.clj 264]
  [sci.impl.vars$binding_conveyor_fn$fn__8727 invoke vars.cljc 147]
  [clojure.core$binding_conveyor_fn$fn__5773 invoke core.clj 2034]
  [clojure.lang.AFn call AFn.java 18]
  [java.util.concurrent.FutureTask run FutureTask.java 264]
  [java.util.concurrent.ThreadPoolExecutor runWorker ThreadPoolExecutor.java 1128]
  [java.util.concurrent.ThreadPoolExecutor$Worker run ThreadPoolExecutor.java 628]
  [java.lang.Thread run Thread.java 834]
  [com.oracle.svm.core.thread.JavaThreads threadStartRoutine JavaThreads.java 519]
  [com.oracle.svm.core.posix.thread.Pos
ixJavaThreads pthreadStartRoutine PosixJavaThreads.java 192]]}

dabrazhe 2021-06-18T17:40:16.111500Z

yes, nrepl connected from Calva in VSC on the mac; the trace in thread above

borkdude 2021-06-18T17:41:00.111600Z

so the issue is likely that you are calling zero? on a nil value

borkdude 2021-06-18T17:41:09.111800Z

but you probably already guessed this

borkdude 2021-06-18T17:41:24.112Z

when invoking the script from the command line you will get a proper stack trace from bb itself

borkdude 2021-06-18T17:41:34.112200Z

but the nrepl environment doesn't have this yet, I think

dabrazhe 2021-06-18T17:41:35.112400Z

Yes, searching in the editor for zero? :))

borkdude 2021-06-18T17:43:29.112600Z

when I evaluate:

(defn foo []
  (zero? nil))

(foo)
I see
clojure.lang.ExceptionInfo: null
{:type :sci/error, :line 4, :column 3, :message nil, :sci.impl/callstack #object[clojure.lang.Delay 0x4e72f87f {:status :pending, :val nil}], :file "\n\n(defn foo []\n  (zero? nil))\n", :locals {}}
as the first lines

borkdude 2021-06-18T17:43:41.112800Z

and this gives you some clue where to look, usually

borkdude 2021-06-18T17:44:24.113Z

but with the command line get:

$ bb /tmp/foo.clj
----- Error --------------------------------------------------------------------
Type:     java.lang.NullPointerException
Location: /tmp/foo.clj:4:3

----- Context ------------------------------------------------------------------
1:
2:
3: (defn foo []
4:   (zero? nil))
     ^---
5:
6: (foo)

----- Stack trace --------------------------------------------------------------
clojure.core/zero? - <built-in>
user/foo           - /tmp/foo.clj:4:3
user/foo           - /tmp/foo.clj:3:1
user               - /tmp/foo.clj:6:1

borkdude 2021-06-18T17:44:29.113200Z

which is much better

dabrazhe 2021-06-18T17:50:00.113400Z

is there a way I can impove it on my end in repl? : )

borkdude 2021-06-18T17:50:32.113600Z

I don't think so, at the moment

2021-06-18T22:08:36.118900Z

Is there some Babashka-compatible templating engine for Clojure? When I say templating engine, I mean for instance ERB in Ruby (`<%= eval_expr(whatevs) %>`) or &lt;?php in PHP. What I'm trying to do: I have a README template which is inherits a lot of data from the monorepo's README, but needs substituting some project-specific stuff.

borkdude 2021-06-18T22:09:22.119300Z

@jakub.stastny.pt_serv babashka has Selmer built-in :)

2021-06-18T22:09:39.119800Z

Great! Thanks @borkdude!

borkdude 2021-06-18T22:09:42.120Z

https://github.com/yogthos/Selmer