DSL Guild Hot Rods

Lisp Dialect

Common Lisp

Synopsis

Because Lisp has such a simple syntax (everything is delimited with parentheses), it is easy to use it to build your own custom programming language, designed for a specific domain. Such domain-specific languages (DSLs) tend to make heavy use of the Lisp macro system. They represent an extreme form of macro programming, transforming Lisp into a completely new programming language.

image with no caption

Explanation

This is an example of code that uses a DSL to build an HTML page. In this case, the page displays “Hello World” in a browser, with the second word rendered in bold. The html and body commands (macros created for the HTML library in Chapter 16) generate opening and closing tags that will contain the body of the page . Then it calls the regular Lisp function princ to generate the text. The second word is wrapped in another custom DSL command, bold , which generates opening and closing bold tags around the specified text.

Example A-5. Example

 (html (body (princ "Hello ")
             (bold (princ "World!"))))

Weakness

Since DSLs are programming languages you create all by yourself, you can definitely shoot yourself in the foot if you aren’t careful. It’s easy to create code in a language that is impossible for others (and perhaps even you) to understand.

Chapter 17 discusses DSLs, including the DSL that allows you to write HTML directly inside your Lisp code, as shown in this example.

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

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