3 ms·
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
by dmux 4y ago
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 https://news.ycombinator.com/item?id=33705558
[1] https://github.com/norvig/paip-lisp/blob/main/docs/chapter2.md#21-a-grammar-for-a-subset-of-english https://github.com/norvig/paip-lisp/blob/main/docs/chapter2....