Programming at the REPL: Data Visualization
clojure.org
clojure.org
For example, you can start a Babashka nREPL by running bb --nrepl-server and connect an Clojure editor to it. Then you can do a lot of fun stuff from there. For example, if you have osquery installed, then you can start querying your system for all kinds of stuff, get data back in EDN and manipulate it using standard Clojure functions:
(require '[clojure.java.shell :refer [sh]]
'[cheshire.core :as json])
(defn osquery [query]
(let [{:keys [exit out err]} (sh "osqueryi" "--json" query)]
(if (zero? exit)
(json/decode out true)
(throw (Exception. err)))))
=> (osquery "select * from routes where destination = '::1'")
=> ({:hopcount "0",
:interface "lo0",
:mtu "16384",
:type "local",
:source "",
:gateway "::1",
:netmask "128",
:flags "2098181",
:destination "::1",
:metric "0"})
I find I often just leave a bb nREPL running with Calva connected to it and some scripts to do common system tasks in it.Shells like Powershell and Fish are the closest to it, due to their integration with programming language and OS APIs.
Emacs is a shadow of the REPL experience from using a Lisp Machine.
It would reseat the base os user interaction to something cleaner and leaner IMO.
import subprocess
import json
def osquery(query):
return json.loads(subprocess.check_output(["osqueryi", "--json", query]))
#>>> osquery("select * from routes where destination = '::1'")
#>>> [{'destination': '::1', 'flags': '2098181', 'gateway': '::1', 'hopcount': '0', 'interface': 'lo0', 'metric': '0', 'mtu': '16384', 'netmask': '128', 'source': '', 'type': 'local'}]
I hadn't heard of osquery - thanks for pointing me to that!- It is rare that this problem is the limiting factor. In Emacs, which has horrible problems rendering long lines, usually by the time I realise there is a visualisation problem my editor has died.
- There is a thin band between too-big-to-print and too-big-to-visualise where this tool is useful. Almost all practical data seems to fall outside this range.
That said, Clojure already has some good tools for solving this problem. Immutable data structures and good generic primitives that are easy to inspect make it fun to deal with inspecting objects.
Sounds like the problem is your editor, not the Clojure namespace :)
Maybe try a real editor, such as vim/neovim ;) It gets a bit bogged down, even on my desktop computer, but at least it never crashes.
And I see I accidentally wrote "the problem" instead of "this problem". I fixed that.
There are a lot of debugging and data visualization tools for the repl with features I haven't found in Common Lisp like :
- https://github.com/jpmonettas/flow-storm-debugger (which I'm actively working on)
> - Instrument any Clojure form
This would be Stickers: annotate any Lisp form with a sticker, run your code, interactively walk through the recordings.
https://joaotavora.github.io/sly/#Stickers
> - Provide a GUI to explore your values and execution flow
SLY has an improved trace dialog: https://joaotavora.github.io/sly/#Trace-Dialog Also LispWorks' visual stepper is easier to use than SLY or Slime's. There is also an in-progress portable visual stepper for CL: https://zenodo.org/record/3742759
> time travel stepper
ah. Nice job.
Yeah I don't know how stickers trace code, but FlowStorm tracing debugger takes advantage of the immutable data structures used everywhere and by default in Clojure. You can then instrument entire code bases, run them, and tracing is just a matter of retaining(leaking) pointers of every intermediate expression so the GC doesn't collect them. I don't think this is possible when working with mutable objects, since then only way would be to somehow serialize the objects involved at every step so you can analyze the data later, which is prohibitively expensive in most situations.