Hacker News new | ask | show | jobs
by brundolf 1302 days ago
This is what I always heard Lisp was best at. Instead of making totally new languages (with parsers, tooling, etc) you'd create little DSLs within your own code in the form of macros: come up with a "little language" for describing one part of your app, write a macro for it, and then it integrates smoothly with everything around it

Whether or not you agree this philosophy is a good one, and whether or not you like Lisp specifically, I think we can all agree that macros (in whichever language) are a much better way to do it than creating a bunch of tiny languages from scratch. I was surprised not to see the word "macro" appear in the article at all

2 comments

Lisp macros are nice, but as Gumby said above [0] a common approach is to use Lisp's quoting abilities to construct a data structure that represents the problem at hand (in its own terms) and then create functions to parse / manipulate that data structure.

A classic example comes from Peter Norvig's "Principles of Artificial Intelligence" wherein he defines a subset of English grammar as a data structure [1]:

  '((sentence -> (noun-phrase verb-phrase))
    (noun-phrase -> (Article Noun))
    (verb-phrase -> (Verb noun-phrase))
    (Article -> the a)
    (Noun -> man ball woman table)
    (Verb -> hit took saw liked)))
He then goes on to define a function "generate" that uses the above to create simplistic English sentences.

Additional rules can be added by a non-programmar so long as they understand how their domain logic has been mapped to Lisp.

[0] https://news.ycombinator.com/item?id=33705558

[1] https://github.com/norvig/paip-lisp/blob/main/docs/chapter2....

Macros are very hard to write tooling for, and hence difficult to author and use. I think that, perhaps something like Polyglot GraalVM[1], which was designed to host many languages and let them all seamlessly talk with each other, while automatically making existing tooling "just work" with any new languages created with the framework [2] would be a better way.

[1] https://www.graalvm.org/22.0/reference-manual/polyglot-progr...

[2] https://www.graalvm.org/22.3/graalvm-as-a-platform/implement...