Cover Material, Copyright, and License
Preface
- Requests from the Author
- Setting Up Your Development Environment
- What is Lisp Programming Style?
- Hy is Python, But With a Lisp Syntax
- Acknowledgements
Introduction to the Hy Language
- Using Python Libraries
- Global vs. Local Variables
- Using Python Code in Hy Programs
- Using Hy Libraries in Python Programs
- Replacing the Python slice (cut) Notation with the Hy Functional Form
- Iterating Through a List With Index of Each Element
- Formatted Output
- Importing Libraries from Different Directories on Your Laptop
- Hy Looks Like Clojure: How Similar Are They?
- Plotting Data Using the Numpy and the Matplotlib Libraries
- Bonus Points: Configuration for macOS and iTerm2 for Generating Plots Inline in a Hy REPL and Shell
- Modern Hy and Python 3.12–3.15: What Changed Since Hy 1.1
- Optional Practice Problems
Why Lisp?
- I Hated the Waterfall Method in the 1970s but Learned to Love a Bottom-Up Programming Style
- First Introduction to Lisp
- Commercial Product Development and Deployment Using Lisp
- Performing Bottom Up Development Inside a REPL is a Lifestyle Choice
Macros and Metaprogramming: The Lisp Advantage
- What You Will Build
- Why It Matters
- The Hy Angle and the Python Equivalent
- Run It
- How It Works
- Tests
- Wrap Up
- Exercises
- Further Reading
Hy Tooling, Packaging, REPL, and Types
- What You Will Build
- Why It Matters
- The Hy Angle
- Python Equivalent
- Run It
- 1. The 10-Minute
uvWorkflow - 2. Project Layout: Scripts vs. Libraries
- 3. Interop Between Hy and Python
- 4. Packaging a Hy Library (
pyproject.tomland Wheels) - 5. Testing Hy Packages with
pytest - 6. Interactive REPL Workflow (
HYSTARTUP,--spy, andhy2py) - 7. Debugging with
breakpoint,pdb, and Name-Mangling Surprises - 8. Static Type Checking with
#^,deftype,hy2py, andmypy - 9. Editor and LSP Options
- 10. Formatting and Linting
- 11. Continuous Integration and Release Checklist
- 12. Migration Tools:
hy2pyandpy2hy - Wrap Up
- Exercises
- Further Reading
Writing Web Applications
- Getting Started With Flask: Using Python Decorators in Hy
- Using Jinja2 Templates To Generate HTML
- Handling HTTP Sessions and Cookies
- Deploying Hy Language Flask Apps to Google Cloud Platform AppEngine
- Wrap Up
- Optional Practice Problems
Responsible Web Scraping
- Using the Python BeautifulSoup Library in the Hy Language
- Getting HTML Links from the DemocracyNow.org News Web Site
- Getting Summaries of Front Page from the NPR.org News Web Site
- Optional Practice Problems
Async and Concurrent Hy
- What You Will Build
- Why It Matters
- The Concurrency Map
- The Hy Angle
- Python Equivalent (
hy2py) - Run It
- How It Works
- Tests
- Wrap Up
- Optional Practice Problems
- Further Reading
Knowledge Graph Visualization with Hy and GraphViz
- What This Program Does
- The Input Data Format
- Complete Annotated Source Code
- Running the Program
- Project Setup
- Key Hy Concepts Demonstrated
- Summary
- Optional Practice Problems
Deep Learning
- Simple Multi-layer Perceptron Neural Networks
- Deep Learning
- Using Keras and TensorFlow to Model The Wisconsin Cancer Data Set
- Using a LSTM Recurrent Neural Network to Generate English Text Similar to the Philosopher Nietzsche’s Writing
- Optional Practice Problems
Natural Language Processing
- Exploring the spaCy Library
- Implementing a HyNLP Wrapper for the Python spaCy Library
- Wrap-up
- Optional Practice Problems
Datastores
- Sqlite
- PostgreSQL
- RDF Data Using the “rdflib” Library
- Wrap-up
- Optional Practice Problems
Linked Data, the Semantic Web, and Knowledge Graphs
- Understanding the Resource Description Framework (RDF)
- Resource Namespaces Provided in rdflib
- Putting it Together: Building and Querying a FOAF Graph
- Understanding the SPARQL Query Language
- Wrap-up
- Optional Practice Problems
Implementing a Simple RDF Datastore and SPARQL Engine in Hy
- The Core Concept
- Example Usage
- Walkthrough of the Hy Implementation
- Conclusion
- Optional Practice Problems
Knowledge Graph Creator
- Recommended Industrial Use of Knowledge Graphs
- Design of KGCreator Application
- Problems with using Literal Values in RDF
- Revisiting This Example Using URIs Instead of Literal Values
- Wrap-up
- Optional Practice Problems
Knowledge Graph Navigator
- Review of NLP Utilities Used in Application
- Utilities to Colorize SPARQL and Generated Output
- Text Utilities for Queries and Results
- Finishing the Main Function for KGN
- Wrap-up
- Optional Practice Problems
Knowledge Base Navigator: Building an AI-Powered Information System
- Project Overview
- Project Structure
- Core Implementation
- Running the Application
- Key Takeaways
- Comparison with KGN
- Environment Setup
- Optional Practice Problems
Using OpenAI GPT
- OpenAI Text Completion API
- Optional Practice Problems
Using Google Gemini API
- REST Interface
- Using Google’s Python Package to Access Gemini
- New Experimental Gemini Interactions APIs
- Wrap Up for Using the Gemini APIs
- Optional Practice Problems
Running Local LLMs Using Ollama
- Completions
- Tool Use
- Wrap Up for Running Local LLMs Using Ollama
- Optional Practice Problems
Agents Using the Agno Agent Framework Running On a Local Ollama Model
- An Agent For Answering Questions About A Specific Web Site
- Wrap Up for Agno Agent Example
- Optional Practice Problems
Using Perplexity Sonar Model for Combined Web Search and LLM Based Reasoning
- A Hy Language Client Library for Perplexity
- Example Output
- Wrap Up for Using Perplexity
- Optional Practice Problems
Using LangChain to Chain Together Large Language Models
- Installing Necessary Packages
- Basic Usage and Examples
- Creating Embeddings
- Using LangChain Vector Stores to Query Documents
- LangChain Wrap Up
- Optional Practice Problems
Large Language Models Experiments Using Google Colab
RAG Using zvec Vector Datastore and Local Model
- Introduction and Architecture
- Design Analysis: Dependency Minimization
- Implementation Walkthrough
- Example Run
- Wrap Up for RAG Using zvec Vector Datastore and Local Model
- Optional Practice Problems
Evaluating and Operating LLM Applications
- What You Will Build
- Why It Matters
- The Hy Angle
- Python Equivalent and Macro Expansion
- Input Data Format
- Run It
- Interpreting the Results: Avoid Metric Worship
- How It Works
- Putting Evaluations in Continuous Integration (CI)
- Tests
- Wrap Up
- Optional Practice Problems
- Further Reading
Symbolic Mathematics
- Project Overview
- The Data Layer: data.hy
- Symbolic Differentiation: differentiation.hy
- Symbolic Integration: integration.hy
- Design Notes: From Common Lisp to Hy
- Running the Full Test Suite
- Summary
- Optional Practice Problems
NSK: A Neural-Symbolic Knowledge Graph Engine
- Project Overview
- A First Session
- Terms and Unification: terms.hy
- The Triplestore: store.hy
- The Query Engine: query.hy
- The Neural Layer: neural.hy
- The REPL: repl.hy
- The REST Server: server.hy
- Testing Without a Model
- Differences from the Common Lisp Version
- Wrap Up
MCP Servers and Tool-Using Agents in Hy
- What You Will Build
- Why It Matters
- The Hy Angle
- Brief Python Equivalent
- Run It
- Seed Data Format
- How It Works
- Connecting to an MCP Host, SDKs, and Remote Transports
- Tests
- Wrap Up
- Optional Practice Problems
- Further Reading
GraphRAG and Knowledge Graph Quality
- What You Will Build
- Why It Matters
- The Hy Angle
- Python Equivalent
- Run It
- How It Works
- Tests
- Wrap Up
- Exercises
- Further Reading