Chapter 17. Domain-Specific Languages

One of the best reasons for using macros is to perform domain-specific language (DSL) programming. DSL programming is an advanced macro programming technique that allows us to solve difficult programming problems by drastically changing the structure and appearance of Lisp code to optimize it for a specialized purpose. Although macros are not strictly necessary for doing DSL programming, by writing a set of macros, you can easily create a DSL in Lisp.

What Is a Domain?

According to the 2000 US Census, the average family in the United States had 1.86 children. Since no individual family has exactly 1.86 children, it is obvious that no particular family is truly perfectly average. In the same way, there is no such thing as an average computer program. Every program is designed to solve a specific problem, and every area of human inquiry, or domain, has its own idiosyncratic requirements that influence programs that solve problems in the given area. With DSLs, we enhance the core of our programming language to take these domain-specific requirements into account, potentially making our resulting code easier to write and understand.

Let’s take a look at some specific domains and create some DSLs that let us easily work within these domains using Lisp. In this chapter, we’ll create two different DSLs. First, we’ll create a DSL for writing scalable vector graphics (SVG) files. Then we’ll write a DSL for creating commands in a text adventure—we’re finally going to upgrade our Wizard’s Adventure Game from Chapter 5 and Chapter 6 to make it fully playable!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.138.178