Fork me on GitHub
#rewrite-clj
<
2022-04-05
>
andrewzhurov11:04:35

Hey, folks! I'm taking a look at rewrite-clj from a perspective of a tool that allows to have Clojure programs as data, as I'm curious about this idea and about an interface to manage such data that would allow to complement my beloved emacs. 🙂 rewrite-clj can read a Clojure program and gives zipper and pareddit interface - that's a nice start!

andrewzhurov11:04:03

I'm curious, can a whole Clojure program with all its Clojure dependencies be read as data?

andrewzhurov11:04:08

E.g., read Clojure program as data, fetch its Clojure dependencies, repeat

borkdude11:04:48

Sure, why not, as long as you implement fetching the deps etc. yourself: any Clojure program as string can be read with rewrite-clj

borkdude11:04:18

What problem would your tool solve? There may already be tools out there that could help you

andrewzhurov11:04:14

I'm curious about it because text-based management of today relies on names (places) to link together a program. E.g., code is given a name some-ns/some-def and anybody who wants code refers to its name, that resolves to code at last at run-time. Lately I've taken look at UnisonWeb, they have program as an immutable structure with names as user-level entities, allowing to label parts of that immutable structure to make sense of it as one sees fit (they have personal dictionaries of content = label , so one person can label code of reduce as foldl , another as Map - it's a personal view of data). I'm curious to have a similar approach for Clojure programs. For that, it seems to me, we could read program as data and decompose code from labels (names). If anybody's curious about reasoning on this problem, https://clojurians.slack.com/archives/C053AK3F9/p1648500209863569. But it's size is way out of hand. 😄

andrewzhurov11:04:32

Are there any tools that could be building blocks for such a solution?

borkdude12:04:52

There are static analysis tools like clj-kondo which can retrieve data from pieces of clojure code. It's based on rewrite-clj. https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md

borkdude12:04:17

There is also tools.analyzer which can return an AST as EDN from Clojure programs.

andrewzhurov12:04:52

> There is also tools.analyzer which can return an AST as EDN from Clojure programs. That sounds interesting, I'll take a look. Thanks. 🙂

borkdude12:04:43

Editor tooling like clojure-lsp is built on the clj-kondo analysis. Depending on what you want that may be already enough

andrewzhurov12:04:29

clj-kondo seems to derive semantical information out of syntactic information rewrite-clj provides, that'll be of use!