rewrite-clj

andrewzhurov 2022-04-05T11:45:35.556389Z

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!

andrewzhurov 2022-04-05T11:46:03.257059Z

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

andrewzhurov 2022-04-05T11:47:08.420289Z

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

borkdude 2022-04-05T11:49:48.397229Z

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

borkdude 2022-04-05T11:50:18.636609Z

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

andrewzhurov 2022-04-05T11:58:14.439489Z

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. 😄

andrewzhurov 2022-04-05T11:59:32.013459Z

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

borkdude 2022-04-05T12:00:52.101329Z

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

borkdude 2022-04-05T12:01:17.228429Z

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

andrewzhurov 2022-04-05T12:02:52.777309Z

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

borkdude 2022-04-05T12:03:43.493659Z

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

andrewzhurov 2022-04-05T12:06:29.580269Z

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

borkdude 2022-04-05T12:08:08.069259Z

indeed :)