Clause and Effect
Clause and Effect
Clocksin
Clause
and Effect
Prolog Programming
for the Working Programmer
Springer
Table of Contents
1. Getting Started 1
1.1 Syntax 2
1.2 Programs 6
1.3 Unification 7
1.4 Execution Model 9
Worksheet 1: Party Pairs 12
Worksheet 2: Drinking Pairs 13
Worksheet 3: Affordable Journeys 14
Worksheet 4: Acyclic Directed Graph 16
2. Data Structures 17
2.1 Square Bracket Notation 19
Worksheet 5: Member.: 20
2.2 Arithmetic 21
Worksheet 6: Length of a List 22
Worksheet 7: Inner Product 23
Worksheet 8: Maximum of a List 24
Worksheet 9: Searching a Cyclic Graph 25
3. Mapping 27
Worksheet 10: Full Maps 30
Worksheet 11: Multiple Choices 31
Worksheet 12: Partial Maps 32
Worksheet 13: Removing Duplicates 33
Worksheet 14: Partial Maps with a Parameter 34
Worksheet 15: Multiple Disjoint Partial Maps 35
Worksheet 16: Multiple Disjoint Partial Maps 36
Worksheet 17: Full Maps with State 37
Worksheet 18: Sequential Maps with State 38
Worksheet 19: Scattered Maps with State 39
viii Table of Contents
5. Difference Structures 55
Worksheet 25: Concatenating Lists 56
Worksheet 26: Rotations of a List 57
Worksheet 27: Linearising 58
5.1 Difference Lists 59
Worksheet 28: Linearising Efficiently 62
Worksheet 29: Linearising Trees 63
Worksheet 30: Difference Structures 64
Worksheet 31: Rotation Revisited 65
Worksheet 32: Max Tree 66
5.2 Solution to Max Tree 67
Index 141