## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

## Book Description

Lisp is a uniquely powerful programming language that, despite its academic reputation, is actually very practical. Land of Lisp brings the language into the real world, teaching readers Lisp by showing them how to write several complete Lisp-based games, including a text adventure, an evolution simulation, and a robot battle. While building these games, readers learn the core concepts of Lisp programming, such as recursion, input/output, object-oriented programming, and macros. And thanks to Lisp's powerful syntax, the example code is short and easy to understand. The book is filled with the author's brilliant Lisp cartoons, which are sure to appeal to many Lisp fans and, in the tradition of all No Starch Press titles, make learning more fun.

1. Land of Lisp
1. Acknowledgments
2. Introduction
3. I. Lisp is Power
1. 1. Getting Started with Lisp
1. Lisp Dialects
2. Getting Started with CLISP
3. What You've Learned
2. 2. Creating Your First Lisp Program
1. The Guess-My-Number Game
2. Defining Global Variables in Lisp
3. Basic Lisp Etiquette
4. Defining Global Functions in Lisp
5. Defining Local Variables in Lisp
6. Defining Local Functions in Lisp
7. What You've Learned
3. 3. Exploring the Syntax of Lisp Code
1. Syntax and Semantics
2. The Building Blocks of Lisp Syntax
3. How Lisp Distinguishes Between Code and Data
4. Lists in Lisp
1. Cons Cells
2. List Functions
3. Nested Lists
5. What You've Learned
4. II. Lisp is Symmetry
1. 4. Making Decisions with Conditions
1. The Symmetry of nil and ()
2. The Conditionals: if and Beyond
3. Cool Tricks with Conditions
4. Comparing Stuff: eq, equal, and More
5. What You've Learned
2. 5. Building a Text Game Engine
2. Describing the Scenery with an Association List
3. Describing the Location
4. Describing the Paths
1. How Quasiquoting Works
2. Describing Multiple Paths at Once
5. Describing Objects at a Specific Location
6. Describing It All
7. Walking Around in Our World
8. Picking Up Objects
9. Checking Our Inventory
10. What You've Learned
3. 6. Interacting with the World: Reading and Printing in Lisp
2. The Symmetry Between Code and Data in Lisp
3. Adding a Custom Interface to Our Game Engine
4. Trying Out Our Fancy New Game Interface
5. The Dangers of read and eval
6. What You've Learned
4. 6.5. lambda: A Function So Important It Deserves Its Own Chapter
5. 7. Going Beyond Basic Lists
1. Exotic Lists
2. Coping with Complicated Data
3. Creating a Graph
1. Generating the DOT Information
2. Turning the DOT File into a Picture
3. Creating a Picture of Our Graph
4. Creating Undirected Graphs
5. What You've Learned
1. The Grand Theft Wumpus Game
2. Defining the Edges of Congestion City
1. Generating Random Edges
2. Looping with the loop Command
3. Preventing Islands
4. Building the Final Edges for Congestion City
3. Building the Nodes for Congestion City
4. Initializing a New Game of Grand Theft Wumpus
5. Drawing a Map of Our City
1. Drawing a City from Partial Knowledge
2. Walking Around Town
6. Let's Hunt Some Wumpus!
7. What You've Learned
7. 9. Advanced Datatypes and Generic Programming
1. Arrays
2. Hash Tables
3. Common Lisp Structures
4. Handling Data in a Generic Way
1. Working with Sequences
2. Creating Your Own Generic Functions with Type Predicates
5. The Orc Battle Game
1. Global Variables for the Player and Monsters
2. Main Game Functions
3. Player Management Functions
4. Helper Functions for Player Attacks
5. Monster Management Functions
6. The Monsters
7. To Battle!
6. What You've Learned
5. III. Lisp is Hacking
1. 10. Looping with the loop Command
1. The loop Macro
1. Some loop Tricks
2. Everything You Ever Wanted to Know About loop
2. Using loop to Evolve!
1. Growing Plants in Our World
2. Creating Animals
3. Simulating a Day in Our World
4. Drawing Our World
5. Creating a User Interface
6. Let's Watch Some Evolution!
7. Explaining the Evolution
3. What You've Learned
2. 11. Printing Text with the format Function
1. Anatomy of the format Function
2. Control Sequences for Printing Lisp Values
3. Control Sequences for Formatting Numbers
4. Printing Multiple Lines of Output
5. Justifying Output
6. Iterating Through Lists Using Control Sequences
7. A Crazy Formatting Trick for Creating Pretty Tables of Data
8. Attack of the Robots!
9. What You've Learned
3. 12. Working with Streams
1. Types of Streams
1. Streams by Type of Resource
2. Streams by Direction
2. Working with Files
3. Working with Sockets
4. String Streams: The Oddball Type
5. What You've Learned
4. 13. Let's Create a Web Server!
1. Error Handling in Common Lisp
2. Writing a Web Server from Scratch
1. How a Web Server Works
2. Request Parameters
4. Testing get-header with a String Stream
5. Parsing the Request Body
6. Our Grand Finale: The serve Function!
3. Building a Dynamic Website
4. What You've Learned
5. 13.5. Functional Programming Is Beautiful
6. IV. Lisp is Science
1. 14. Ramping Lisp Up a Notch with Functional Programming
1. What Is Functional Programming?
2. Anatomy of a Program Written in the Functional Style
3. Higher-Order Programming
4. Why Functional Programming Is Crazy
5. Why Functional Programming Is Fantastic
6. What You've Learned
2. 15. Dice of Doom, a Game Written in the Functional Style
1. The Rules of Dice of Doom
2. A Sample Game of Dice of Doom
3. Implementing Dice of Doom, Version 1
1. Defining Some Global Variables
2. Representing the Game Board
3. Decoupling Dice of Doom's Rules from the Rest of the Game
4. Generating a Game Tree
5. Calculating Passing Moves
6. Calculating Attacking Moves
7. Finding the Neighbors
8. Attacking
9. Reinforcements
10. Trying Out Our New game-tree Function
11. Playing Dice of Doom Against Another Human
4. Creating an Intelligent Computer Opponent
5. Making Dice of Doom Faster
1. Closures
2. Memoization
3. Tail Call Optimization
4. A Sample Game on the 3-by-3 Board
6. What You've Learned
3. 16. The Magic of Lisp Macros
1. A Simple Lisp Macro
2. More Complex Macros
3. Macros: Dangers and Alternatives
4. What You've Learned
4. 17. Domain-Specific Languages
1. What Is a Domain?
2. Writing SVG Files
1. Creating XML and HTML with the tag Macro
2. Creating SVG-Specific Macros and Functions
3. Building a More Complicated SVG Example
3. Creating Custom Game Commands for Wizard's Adventure Game
1. Creating New Game Commands by Hand
2. Let's Try the Completed Wizard's Adventure Game!
4. What You've Learned
5. 18. Lazy Programming
1. Adding Lazy Evaluation to Lisp
2. Dice of Doom, Version 2
3. Making Our AI Work on Larger Game Boards
4. What You've Learned
6. 19. Creating a Graphical, Web-Based Version of Dice of Doom
1. Drawing the Game Board Using the SVG Format
2. Building the Web Server Interface
3. Playing Version 3 of Dice of Doom
4. What You've Learned
7. 20. Making Dice of Doom More Fun
1. Increasing the Number of Players
2. Rolling the Dice
3. Improving the Dice of Doom Reinforcement Rules
4. Conclusion
8. A. Epilogue
1. Functional Guild Cruiser
2. Macro Guild Melee Fighters
3. Restart Guild Armored Fighter
4. Generic Setter Guild Supply Ship
5. DSL Guild Hot Rods
6. CLOS Guild Battleship
7. The Continuation Guild Rocket Pods
8. Brevity Guild Micro Fighter
9. Multicore Guild Formation Fighters
10. The Lazy Guild Frigate
7. Index