Summary: PLAI Ch.1 — Introduction
Table of Contents
Key Claims
- PLAI is structured as a conversation, not a top-down narrative; it includes deliberate mistakes to enforce active reading.
- The book's implementation language is
plai-typed, a statically typed dialect of Racket. Advprog substitutes Common Lisp. define-typeintroduces algebraic data types with named variants;type-casepattern-matches over them. These are PLAI's primary structuring mechanisms.- Type annotations are optional (inference fills in most cases) but preferred for discipline and readability.
- Tests are first-class via the
testform; writing them before function definitions is encouraged.
Summary
Chapter 1 is a brief methodological introduction. Krishnamurthi explains the book's non-linear, conversation-like structure: the reader will encounter mistakes, corrections, and backtracking. This is intentional; passive reading is explicitly discouraged via "Do Now!" prompts.
The chapter introduces the implementation language plai-typed. Key constructs:
define-type- defines an algebraic datatype with named variants, each
carrying typed fields. Analogous to an abstract class with concrete
subclasses in Java, or
defclasshierarchies in Common Lisp. type-case- pattern-matches over a
define-typevalue, binding field names in each branch. Analogous toematchin Common Lisp. test- asserts equality between an expression and an expected value.
Example from the chapter:
(define-type MisspelledAnimal
[caml (humps : number)]
[yacc (height : number)])
(define (good? [ma : MisspelledAnimal]) : boolean
(type-case MisspelledAnimal ma
[caml (humps) (>= humps 2)]
[yacc (height) (> height 2.1)]))
The Common Lisp / tolk equivalent uses defclass hierarchies and
trivia ematch for the same purpose.
Tolk / Advprog Correspondence
| PLAI (plai-typed) | Tolk / Advprog (Common Lisp) |
|---|---|
define-type |
defclass hierarchy under ast-node |
type-case |
ematch (trivia), defmethod-bind |
test |
fiveam test forms |
#lang plai-typed |
package / in-readtable :fare-quasiquote |