☰
↑
←
→
🔍
TOC
Additional Features of Prolog
and the ISO Standard
»
Table of Contents
Table of Contents
What Prolog adds to pure logic programming
The ISO Prolog standard (Slide 2)
An overview of the standard (Slide 3)
The programming interface (Slide 4)
Syntax and operators
Prolog syntax and terminology (Slide 5)
Defining operators (Slide 6)
Operators in use (Slide 7)
An operator of our own
The standard operator table (Slide 8)
Execution and arithmetic
The execution mechanism of classical Prolog (Slide 9)
Built-in arithmetic (Slides 10–12)
Failure versus error
Arithmetic programs (Slide 13)
Goal order now matters in a new way
Exercises
Types, structures and terms
Dynamic checking of basic types (Slide 14)
Recovering some reversibility (Slide 15)
Structure inspection with
functor
(Slide 16)
Structure inspection with
arg
(Slide 17)
Example: arrays (Slides 18–19)
Syntactic sugar for
arg
(Slide 19)
Going further: loops and mutable arrays
Example: subterms of a term (Slide 20)
Higher-order structure inspection:
univ
(Slide 21)
Extending
deriv
with the chain rule
Exercises
Strings, atoms, and creating new atoms (Slide 22)
Meta-logical predicates and term comparison
Meta-logical predicates (Slide 23)
Choosing an implementation by calling mode (Slides 24–25)
Comparing non-ground terms (Slide 26)
Two applications of term comparison (Slide 27)
Revisiting
subterm
, for non-ground terms
Inserting into an ordered list
Input/output
The I/O predicates (Slides 28–29)
Two things to remember when writing terms that will be read back
An example, and a warning (Slide 30)
The cut
The pruning operator (Slides 31–32)
White and green cuts (Slide 33)
White cuts — do not discard solutions
Green cuts — discard correct solutions which are not needed
Red cuts (Slide 34)
Living with red cuts (Slide 35)
Red cuts: the leap year, step by step (Slide 36)
The best fix: make the cut white by writing the missing condition
Delaying the output binding: better, but not enough
Checking the mode explicitly
Better still: stating the mode with an assertion
Exercises
Two more examples worth working through
Meta-calls, higher order and aggregation
Meta-calls and implementing higher order (Slide 37)
Inventing
apply
call/n
and the higher-order library (Slide 38)
maplist
and reversibility
Ciao's
hiord
package (Slide 39)
Aggregation predicates (Slides 40–42)
The set versions:
setof
and
bagof
Exercises
Negation as failure (Slides 43–44)
Ensuring correctness
Exercises
Cut-fail (Slide 45)
Dynamic program modification and meta-interpreters
Modifying the program at run time (Slide 46)
Assert and retract in action (Slide 47)
Lemmas: the one clearly good use (Slide 48)
Exercises
Meta-interpreters (Slide 49)
Extending the meta-interpreter (Slide 50)
Exercises
Incomplete data structures
Difference lists (Slide 51)
Playing with difference lists (Slide 52)
Quicksort with ordinary lists (Slides 53–54)
Which argument should be a difference list?
Quicksort with difference lists, in three steps (Slides 55–57)
Exercises
Parsing and grammars
Parsing with
append
and ordinary lists (Slide 58)
The same, with difference lists (Slide 59)
The same again, with string syntax (Slide 60)
Definite clause grammars (Slides 61–62)
Parsing with actions (Slide 63)
Exercises
What is left, and where to look
Other issues in Prolog (Slide 64)
Libraries (Slide 65)
Extensions, taking Ciao as the example (Slides 66–68)