Comment

Comment by malisper

The one feature that really differentiates Lisp from other languages is its macro system. Macros allow you to give arbitrary semantic meaning to an expression. The expression (a b c) could quite literally do anything. It could set the value of b to the value of c (setf), it could call the procedure named by c with the value of b and store that value back into b, or define a class called b which has a local variable called c. Macros allow programmers to build arbitrarily complex DSLs all within Lisp.

A couple examples of some really great macros are those in PAIP[0]. In particular, look at the defrule macro[1][2] for a version of mycin[3]. The macro defrule is a DSL for creating rules about how to diagnose different bacteria. Also look at the rule macro[4][5] for defining DCGs[6], a way to parse natural language.

A great way to learn more about macros is through reading On Lisp[7], in which Paul Graham explores some of the really crazy things that are possible with macros, including implementing continuations[8], creating a DSL for ATNs[9] (another way to parse natural language), and even implementing an object system.

[0] http://norvig.com/paip.html

[1] http://norvig.com/paip/mycin-r.lisp

[2] http://norvig.com/paip/mycin.lisp

[3] http://en.wikipedia.org/wiki/Mycin

[4] http://norvig.com/paip/grammar.lisp

[5] http://norvig.com/paip/unifgram.lisp

[6] http://en.wikipedia.org/wiki/Definite_clause_grammar

[7] http://www.paulgraham.com/onlisp.html

[8] http://en.wikipedia.org/wiki/Continuation

[9] http://en.wikipedia.org/wiki/Augmented_transition_network

parent malisper 12 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton