This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-29
Channels
- # aws (8)
- # babashka (45)
- # beginners (83)
- # cider (23)
- # clj-on-windows (4)
- # cljdoc (23)
- # clojars (6)
- # clojure (68)
- # clojure-dev (33)
- # clojure-europe (75)
- # clojure-nl (1)
- # clojure-uk (4)
- # clojurescript (14)
- # conjure (6)
- # data-science (15)
- # datascript (7)
- # datomic (47)
- # docker (15)
- # events (1)
- # fulcro (4)
- # graphql (3)
- # jobs (4)
- # lsp (14)
- # nginx (2)
- # nrepl (2)
- # off-topic (41)
- # pathom (18)
- # pedestal (1)
- # polylith (72)
- # reitit (8)
- # reveal (1)
- # shadow-cljs (48)
- # tools-build (11)
- # tools-deps (24)
- # xtdb (8)
I'm fond of the debux library for clj/cljs. Is there a pod/lib that provides similar functionality for debugging babashka?
@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.
This may serve as a basic alternative though: https://github.com/technomancy/limit-break
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
@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
@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)
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"}
This conversation is from more than a year ago and probably no longer relevant. You don’t need spartan spec anymore
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 worksomg, it tries to load the clojurescript compiler, no that doesn't currently work in bb
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.
oh fork, I have to scroll back to the original conversation. you have a long attention span, spanning over multiple years :)
$ 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
@UPD88PGNT The author of debux was keen on having babashka compatibility so I added this PR: https://github.com/philoskim/debux/pull/30
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
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]))))
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]
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
Though I also made a mixin that would convert :style/padding 0
to :style {:padding 0}
, like
[:div :id "section1"
:style/padding 0
"hi"]
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 whateverOr you could pour singular values and key/vals in any order and only the single value order matters
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
The code is on another computer but I can post it up if you're interested. It's a pretty simple function