Cover Material, Copyright, and License
Preface
- How To Read This Book?
- Requests from the Author
- Why Use Common Lisp?
- Acknowledgments
- Setting Up Your Common Lisp Development System and Quicklisp
Introduction
- Why Did I Write this Book?
- Free Software Tools for Common Lisp Programming
- Making Book Examples Run Portably on Most Common Lisp Implementations
- How is Lisp Different from Languages like Java and C++?
- Advantages of Working in a Lisp Environment
Common Lisp Basics
- Getting Started with SBCL
- Making the repl Nicer using rlwrap
- The Basics of Lisp Programming
- Symbols
- Operations on Lists
- Using Arrays and Vectors
- Using Strings
- Using Hash Tables
- Using Eval to Evaluate Lisp Forms
- Using a Text Editor to Edit Lisp Source Files
- Recovering from Errors
- Garbage Collection
- Loading your Working Environment Quickly
- Functional Programming Concepts
Quicklisp
- Using Quicklisp to Find Packages
- Fixing Quicklisp Problems
- Using Quicklisp to Configure Emacs and Slime
Defining Lisp Functions
- Using Lambda Forms
- Using Recursion
- Closures
- Using the Function eval
Defining Common Lisp Macros
- Example Macro
- Using the Splicing Operator
- Using macroexpand-1
Using Common Lisp Loop Macros
- dolist
- dotimes
- do
- Using the loop Special Form to Iterate Over Vectors or Arrays
Common Lisp Package System
Input and Output
- The Lisp read and read-line Functions
- Lisp Printing Functions
Plotting Data
- Implementing the Library
- Packaging as a Quicklisp Project
Common Lisp Object System - CLOS
- Example of Using a CLOS Class
- Implementation of the HTMLstream Class
- Using Defstruct or CLOS
Network Programming
- An introduction to Drakma
- An introduction to Hunchentoot
- Complete REST Client Server Example Using JSON for Data Serialization
- Network Programming Wrap Up
One Interface for Brave, Tavily, and Perplexity Web Search APIs
- Two Kinds of Search API
- The Shared Data Model
- Source Code
- Setting the API Keys
- Running the Code
- Interpreting the Results
- Adding a Provider
- Error Handling
- Testing the Library
- Wrap Up
- Optional Practice Problems
Accessing Relational Databases
- Database Wrap Up
Natural Language Processing
- Loading and Running the NLP Library
- Part of Speech Tagging
- Categorizing Text
- Detecting People’s Names and Place Names
- Summarizing Text
- Text Mining
Information Gathering Using DBPedia Lookup
- Wrap Up
Web Scraping
- Shared Utilities: utils.lisp
- Extracting HTML Headers
- Extracting Page Content as Plain Text
- Converting a Web Page to Markdown
- Wrap Up
- Optional Practice Problems
Backpropagation Neural Networks
Hopfield Neural Networks
Anomaly Detection
- What Is a Gaussian Distribution?
- How the Detector Works
- The Wisconsin Breast Cancer Dataset
- Project Structure
- Walking Through the Code
- Running the Example
- Using the API in Your Own Code
- Understanding the Evaluation Metrics
- Wrap Up
Semantic Web and Linked Data
- Resource Description Framework (RDF) Data Model
- Extending RDF with RDF Schema
- The SPARQL Query Language
- Case Study: Using SPARQL to Find Information about Board of Directors Members of Corporations and Organizations
- Installing the Apache Jena Fuseki RDF Server
- Common Lisp Client Examples for the Apache Jena Fuseki RDF Server
Implementing a Simple RDF Datastore and Partial SPARQL Support in Common Lisp
- 1. RDF Triple Structure
- 2. RDF Datastore
- 3. Basic Datastore Operations
- 4. Query Support
- 5. SPARQL Query Structure
- 6. SPARQL Query Parsing
- 7. Query Execution
- 8. Result Projection
- 9. Main Query Execution
- Conclusion
- Optional Practice Problems
Automatically Generating Data for Knowledge Graphs
- Implementation Notes
- Generating RDF Data
- Generating Data for the Neo4j Graph Database
- Implementing the Top Level Application APIs
- Implementing The Web Interface
- Creating a Standalone Application Using SBCL
- Augmenting RDF Triples in a Knowledge Graph Using DBPedia
- KGCreator Wrap Up
Knowledge Graph Sampler for Creating Small Custom Knowledge Graphs
- Project Definition
- Overview of Architecture
- Code
Knowledge Graph Navigator Common Library Implementation
- Example Output
- Project Configuration and Running the Application
- Review of NLP Utilities Used in Application
- Developing Low-Level SPARQL Utilities
- Implementing the Caching Layer
- Utilities in the Main Library File kgn-common.lisp
- Wrap-up
Knowledge Graph Navigator Text-Based User Interface
- Example Output
- Text User Interface Implementation
- Wrap-up
Knowledge Graph Navigator User Interface Using LispWorks CAPI
- Project Configuration and Running the Application
- Utilities to Colorize SPARQL and Generated Output
- Main Implementation File kgn-capi-ui.lisp
- User Interface Utilites File user-interface.lisp
- User Interface CAPI Options Panes Definition File option-pane.lisp
- Using LispWorks CAPI UI Toolkit
- Wrap-up
Building a MicroGPT in Common Lisp
- Introduction
- Demystifying the Core Components
- Conclusion
- Complete Source Code Listing for
microgpt.lisp - Wrap Up
One Library, Many LLM Providers: the litelm Library
- The Provider Registry
- Model Strings: “provider/model-name”
- Finding the API Key
- Headers and URLs: Small Pure Helpers
- The Shared Send Path in completion
- Embeddings Share the Same Path
- Messages and Tools in Lisp Clothing
- Streaming and Errors, Same Everywhere
- Trying It Out
- Adding a Provider or Swapping an Endpoint
- litelm Chapter Wrap Up
- Optional Practice Problems
Using Local LLMs With Ollama
- Design Notes (Optional Material)
- Implementation of Common Helper Code
- Implementation of Generative AI Functionality
- Implementation of Tool Use/Function Calling Generative AI Functionality
- Using Built In Web Search Tool on Ollama Cloud
- Ollama Chapter Wrap Up
- Optional Practice Problems
Image Processing With Local Ollama Models
- Design Notes for the Example code
- Code to Process Images
- Example Program Output
- Optional Practice Problems
Knowledge Base Navigator: Building an AI-Powered Information System
- Project Overview
- Project Structure
- Core Implementation
- Running the Application
- Key Takeaways
- Dependencies
- Environment Setup
Interfacing with External Programs: A Lightpanda Browser Client
- The Problem: JavaScript-Rendered Web Content
- Project Structure
- Configuration
- Running External Programs with UIOP
- String Processing: Extracting Links
- The Main API Function
- Helper Functions
- Usage Examples
- Compatibility Package
- Key Code Style Takeaways
Using a Local Document Embeddings Vector Database for Semantically Querying Your Own Data
- Overview of Local Embeddings Vector Database to Enhance the Use of GPT3 APIs With Local Documents
- Implementing a Local Vector Database for Document Embeddings
- Using Local Embeddings Vector Database With OpenAI GPT APIs
- Testing Local Embeddings Vector Database With OpenAI GPT APIs
- Adding Chat History
- Wrap Up for Using Local Embeddings Vector Database to Enhance the Use of GPT5 APIs With Local Documents
- Optional Practice Problems
Agentic RAG Using the Gemini LLM APIs
- Overview of the Agentic RAG Architecture
- Project Structure
- Computing Embeddings With the Gemini API
- In-Memory Vector Store
- The Multi-Agent Pipeline
- Top-Level API and Demo
- Running the Example
- Offline Tests
- Wrap Up for Agentic RAG
- Optional Practice Problems
Prompt Engineering for Large Language Models
- Two Types of LLMS
- Prompt Examples
- Prompt Engineering Wrapup
Client Library for the Google Gemini LLM APIs
- Relationship to the litelm library
- Example Use
- Using Google’s “Grounding Search”
- Using Google’s “Grounding Search” With Citations
- Mixing Local Tools with Google Platform Tools Using the Interactions APIs.
- Optional Practice Problems
AutoContext: Prepare Effective Prompts with Context for LLM Queries
- Implementing the BM25 Algorithm
- Implementing Vectorization of Text and Semantic Similarity
- Implementation of Main Program
- Example Generated Prompt with Context
- Wrap Up For Generating Prompts with Contexts
- Optional Practice Problems
AI-Powered Text Adventure Game
- Architecture
- The System Prompt
- The Game Code
- The Ollama Chat Function
- Running the Game
- Example Session
- What Makes This Work
- Customizing the Adventure
- Wrap Up
- Optional Practice Problems
Symbolic Mathematics in Common Lisp
- The Data Layer
- Symbolic Differentiation
- Symbolic Integration
- Wrap Up
- Optional Practice Problems
WebKit Applications - macOS Only
- Architecture Overview
- Prerequisites and Building
- Project Structure
- The C Shim
- CFFI Bindings
- The Bridge: JS <—> Lisp Communication
- High-Level API
- Example 1: Hello World
- Example 2: Counter App with Bridge
- Example 3: Markdown File Viewer
- API Reference Summary
- Key Takeaways
- Optional Practice Problems
A Persistent LLM Cache with SQLite
- The System Definition
- The Class and the Schema
- Adding an Entry
- Escaping LIKE Metacharacters
- Looking Up Entries
- Housekeeping
- Testing the Library
- Key Takeaways
- Optional Practice Problems
A Daily-Use Gemini REPL with Search Grounding and Persistent Cache
- Two Ways to Reach Gemini
- How It Works
- Prerequisites
- Project Structure
- The Main Application
- Running the Tool
- Example Session
- REPL Command Reference
- Key Takeaways
Building an AI Coding Assistant for Common Lisp
- Architecture
- Project Structure
- File-System Tools
- The Agent Core
- Installation
- Usage Examples
- Example Session
- Key Takeaways
- Wrap Up
- Optional Practice Problems
Hacking the SBCL REPL
- Shell Access via a Reader Macro
- AI Coding Agent Integration
Building a Neural-Symbolic Knowledge Graph Engine in Common Lisp
- Two ways to know things
- What we will build
- The package
- Unification: matching by structure
- The triplestore and its durable log
- A natural query syntax with reader macros
- The query engine
- Self-contained JSON
- The neural fallback layer
- The interactive REPL
- The optional REST server
- Command-line entry point and builds
- Running NSK
- Interpreting the results
- Testing the engine
- Wrap up
- Optional practice problems
Overview of Probability
- The result that surprises everyone
- Fact, prediction, or wishful thinking?
- Bayes in one line
- The library
- Frequentists vs. Bayesians
- The frequentist check
- The vocabulary you need
- Practice problems
- Wrap up