Ask HN: LISPers, do you use homoiconicity (code-as-data)?

3 points by lopatin ↗ HN
So IMO the biggest reason to use LISP over other languages that also provide first class functions and closures is homoiconicity. On the other hand, when I was using LISPs as my primary language, I found that I wasn't using this feature as much as I imagined I would. And when I did, it was arguably superfluous.

So my question is two fold:

1. Do you have any examples (aside from PL/compiler related work) that LISPs code-as-data features are used to solve problems that otherwise would have been much harder?

2. Given that you've likely substituted 50,000 lines of Java code with 300 lines of LISP, it goes without saying that you are a lone wolf programmer. But do you, yourself, ever have trouble understanding what you've written after some time? Also, how do your refactors go? Do you do them at all?

8 comments

[ 2.6 ms ] story [ 11.8 ms ] thread
I'm new to LISP but the way Hiccup (https://github.com/weavejester/hiccup) in Clojure allows to embeds HTML in Clojure code feels really powerful.
Yeah I think HTML is a good exams of a domain spec language. Instead of putting HTML in a dead string it can be in a parsible lisp object can be manipulated with editor commands. Of course you can do the opposite and have HTML file with lisp code embedded. Ie like a jsp in Java. But with lisp all this is at your finger tips. You don't need to wait for a big billionaire company to make html syntax for you. Or unit test supported at the language level. Or whatever
Embedded SQL is also quite common.
Yes but in my experience (with korma, which I don't like) I've not used a lot of programmatic modification of SQL queries. At the end of the day, I write a query for "a data question", and I add parameters to the question, but it is rare for me that I need to "create new types of questions" on the fly.

Even if I need to compose a query for a more flexible questioning than using a value parameters, this is something that typically could be done by combining 2 or 3 substrings, there is not typically the need to work queries as much as I do with HTML and hiccup.

So at the end I moved to HugSQL (the modern+popular "write your queries in SQL"-philosophy library) instead of YesQL (the modern+popular "write your queries in clojure"-philosophy library, similar in approach to korma).

Yes, sometimes that suffices. Other times you have to translate an ad–hoc query language encoded in the query parameters of a url into SQL queries, and then it would be really nice to have some way of manipulating them other than just string concatenation. That's a month of my life I’ll never get back.
Ok, fair point, you don’t need it until you need it and you wish you had it :)
(comment deleted)
Quite a lot, actually.

Polynomials can be easily manipulated, such as taking a derivative, and the result is still valid executable code.

Macros use homoiconicity all the time, doing code walking and code expansion.

Functions can construct and return functions easily.