Fork me on GitHub
#babashka
<
2021-09-29
>
Carl10:09:27

I'm fond of the debux library for clj/cljs. Is there a pod/lib that provides similar functionality for debugging babashka?

borkdude10:09:36

@carl.kamholtz There are a few issues with this lib: it's loading the clojurescript analyzer which can't run in bb. Also it's loading clojure.spec.alpha but this may be alleviated with spartan.spec which is a drop-in replacement for the most common parts of spec.

borkdude10:09:51

This may serve as a basic alternative though: https://github.com/technomancy/limit-break

borkdude10:09:30

You can open a REPL at any point in your program and then inspect the locals, and exit the REPL when done to continue program execution

Carl10:09:37

Interesting! Thanks for the quick reply 😊

borkdude10:09:45

@carl.kamholtz Wow, it seems I've got it working:

$ bb  "(require 'spartan.spec) (use 'debux.core) (* 2 (dbg (+ 10 20)))"

{:ns user, :line 1}
dbg: (+ 10 20) =>
|   30
60

❤️ 1
borkdude11:09:29

The -> examples don't show the output that the README shows, just one output

borkdude11:09:26

let me just push what I've got

borkdude11:09:01

@carl.kamholtz Add a bb.edn like this: https://github.com/borkdude/debux/blob/babashka/bb.edn + that repo as a git dep And then first require (require 'spartan.spec)

Richie03:01:18

Like this?

{:deps {borkdude/spartan.spec {:git/url ""
                               :sha "12947185b4f8b8ff8ee3bc0f19c98dbde54d4c90"}
        borkdude/debux {:git/url ""
                        :sha "0ff1224faf0e3dc9e09f93bc1adc75d7a3e32a0f"}}}
I'm getting
Checking out:  at 0ff1224faf0e3dc9e09f93bc1adc75d7a3e32a0f
Error building classpath. Manifest file not found for borkdude/debux in coordinate #:git{:url "", :sha "0ff1224faf0e3dc9e09f93bc1adc75d7a3e32a0f"}

borkdude08:01:24

This conversation is from more than a year ago and probably no longer relevant. You don’t need spartan spec anymore

borkdude08:01:54

Bb comes with Clojure spec alpha bundled now

Richie12:01:58

Should debux work?

borkdude12:01:10

Have you tried it?

borkdude12:01:10

It seems not yet:

bb -Sdeps '{:deps {philoskim/debux {:mvn/version "0.8.2"}}}' -e "(require '[debux.core])"
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Unable to resolve classname: java.net.MalformedURLException
Data:     {:type :sci/error, :line 231, :column 1, :file "cljs/js_deps.cljc", :phase "analysis"}
Location: cljs/js_deps.cljc:236:7
Phase:    analysis
I'll see if adding that class works

borkdude12:01:24

omg, it tries to load the clojurescript compiler, no that doesn't currently work in bb

borkdude12:01:49

if that lib can avoid it, maybe it could be made to work with bb

Richie14:01:32

Sorry, I only tried your fork and since you said that it kind of worked for you I thought that I shouldn't get the error that I got.

borkdude14:01:44

oh fork, I have to scroll back to the original conversation. you have a long attention span, spanning over multiple years :)

borkdude14:01:30

I'll check out my fork

borkdude15:01:40

$ rlwrap bb -Sdeps '{:deps {debux/debux {:git/url "" :git/sha "ef9f1743ef40be326faa971c87e647fc12d2975d"}}}'
Babashka v1.1.173-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (require '[debux.core :refer [dbg]])
nil
user=> (+ (dbg (+ 1 2 3)) 2)

{:ns user, :line 2}
dbg: (+ 1 2 3) =>
|   6
8

👍 2
Richie15:01:56

Sweet! Thanks!

borkdude10:02:53

@UPD88PGNT The author of debux was keen on having babashka compatibility so I added this PR: https://github.com/philoskim/debux/pull/30

❤️ 4
Richie12:02:58

Awesome! Thanks for working so hard.

borkdude11:09:11

And then it sort of worked for me

borkdude11:09:54

if you just want the kind of simple dbg macro you can also write your own:

user=> (defmacro dbg [& forms] `(do (apply prn (rest '~&form)) (let [res# (do ~@forms)] (prn (symbol "=>") res#) res#)))
#'user/dbg
user=> (dbg (+ 1 2 3))
(+ 1 2 3)
=> 6
6

❤️ 1
borkdude11:09:16

user=> (* 2 (dbg (+ 1 2 3)))
(+ 1 2 3)
=> 6
12

borkdude11:09:05

I'm slowly adopting a new style of arg parsing, currently in neil but might expand it to other CLIs:

(defn parse-opts [opts]
  (let [[cmds opts] (split-with #(not (str/starts-with? % ":")) opts)]
    (into {:cmds cmds}
          (for [[arg-name arg-val] (partition 2 opts)]
            [(keyword (subs arg-name 1)) arg-val]))))

🙌 1
john03:09:23

I created a similar arg passing style recently for higher order hiccup components

john03:09:59

Key value pairs can be placed anywhere in the args list and they get assoc'ed onto an options map... [1 3 :x 'y 4] ;=> [{:x y} 1 3 4]

john03:09:26

It's a more relaxed argument passing syntax for defining components with optional attributes, that would usually go in a context map as the first argument to a reagent component

john03:09:56

like

[:div :id "section1"
      :style {:padding 0}
 "hi"]

john03:09:33

Though I also made a mixin that would convert :style/padding 0 to :style {:padding 0}, like

[:div :id "section1"
      :style/padding 0
 "hi"]

john03:09:51

But if you were to do

[:div 
 :id "section1"
 "hi"
 :style/padding 0
 "there"]
You'd see hi there, so you can spread out the attributes, if you want to group attributes by certain children, for documentation/conveying context or whatever

john03:09:50

Or you could pour singular values and key/vals in any order and only the single value order matters

john03:09:08

But once you grok it, it kinda makes sense as a sorta intuitive idiom, so I figured I might find use for it in other places too

john03:09:11

The code is on another computer but I can post it up if you're interested. It's a pretty simple function

john03:09:10

Like if you ever wanted to allow in the future something like neil add dep clj-kondo/clj-kondo :latest-sha true acme/widgets :version 0.2.0, where you can add multiple libs... but in that case, you'd want to keep track of which options follow which libs

john04:09:15

Wonder if neil could precache the .cpcache somehow. Maybe with an :install option

borkdude11:09:33

This allows multiple "simple" values (subcommands) followed by key-value pairs

borkdude11:09:47

e.g. neil add dep clj-kondo/clj-kondo :latest-sha true

Carl12:09:00

@borkdude you are amazing! Thank you, I'll have a play with it tomorrow