Inductive Sets of Data: Essentials of Programming Languages (Chapter 1)
Inductive Sets of Data: Essentials of Programming Languages (Chapter 1)
Session 6
Recursively Specified Data
We introduce the basic programming tools to write interpreters, ...
The syntax of a language is usually a nested or treelike structure
- Recursion will be at the core of our techniques
We must know
- What kinds of values may occur as arguments to the procedure?
- What kinds of values are legal for the procedure to return?
1. 0 S, and
2. If n S, then n+3 S.
• A natural number n is in S if and only if the statement "n ES" can be derived
from the axioms by using the rules of inference finitely many times
• This makes S the smallest set that is closed under the rules
• These definitions all say the same thing.
• the first version: a top-down definition
• the second version: a bottom-up definition
• the third version: a rules-of-inference version
Inductive Specification
• Definition 1.1.3 (list of integers, top-down) A Scheme list is a list of integers if
and only if either
1. it is the empty list, or
2. it is a pair whose car is an integer and whose cdr is a list of integers.
• Definition 1.1.4 (list of integers, bottom-up) The set List-of-Int is the smallest set of
Scheme lists satisfying the following two properties:
1. () List-of-Int, and
2. if n Int and l List-of-Int, then (n . l) List-of-Int.
Rules of Inference
Definition 1.1.5 (list of integers, rules of inference)
∈ List-of-int
(14 . ())
(3 . (14 . ()))
4. (-7 . (3 . (14. ()))) is a list of integers, because of property 2, since -7 is a integer and (3 . (14 .
())) is a list of integers. Once more we can write this as an instance of the second rule for List-of-
Int.
−7 ∈ 𝑖𝑛𝑡 (3 . (14 . ()))∈ 𝑙𝑖𝑠𝑡 − 𝑜𝑓 − 𝑖𝑛𝑡
(−7 . (3 . (14 . ()))) ∈ 𝑙𝑖𝑠𝑡 − 𝑜𝑓 − 𝑖𝑛𝑡
(14 . ())
(3 . (14 . ()))
(−7 . (3 . (14 . ())))
Defining Sets Using Grammars
List-of-Int::= ()
List-of-Int::= (Int . List-of-Int)
List-of-Int List-of-Int
(Int . List-of-Int) (Int . List-of-Int)
(14 . List-of-Int) (int . ())
(14 . ()) (14 . ())
Other Useful Sets
Definition 1.1.6(S-list , S-exp) Definition 1.1.7(binary tree)
Bintree ::= int | (Symbol Bintree Bintree)
S-list ::= ({s−exp}∗ )
S-exp ::= Symbol | s-list
Here are some example of such tree
1
2
(foo 1 2)
(bar 1 (foo 1 2))
(baz
(bar 1 (foo 1 2)
(biz 4 5)
Other Useful Sets
The lambda calculus is a simple language that consists only of:
• variable references
• procedures that take a single argument
• procedure calls
Definition 1.1.8 (lambda expression)
LcExp ::= Identifier
::= (lambda (Identifier) LcExp)
::= (LcExp LcExp)
where an identifier is any symbol other than lambda.
Lambda Calculus
The identifier in the second production is called the bound variable
• It binds or captures any occurrences of the variable in the body
• Any occurrence of that variable in the body refers to this one
If the expression e is of the form (lambda (y) e'), then the variable x
occurs free in e if and only if y is different from x and x occurs free in e'.