Skip to Content
Programming Languages: Concepts and Implementation
book

Programming Languages: Concepts and Implementation

by Saverio Perugini
December 2021
Beginner
840 pages
47h 29m
English
Jones & Bartlett Learning
Content preview from Programming Languages: Concepts and Implementation

14.7 Going Further in Prolog

14.7.1 Program Control in Prolog: A Binary Tree Example

The following set of facts describes a binary tree (lines 2–3). A path predicate is also included that defines a path between two vertices, with two rules, to be either an edge from X to Y (line 6) or a path from X to Y (line 7) through some intermediate vertex Z such that there is an edge from X to Z and a path from Z to Y:

A set of seven code lines in Prolog with a path predicate.
Description

Notice that the comma in the body (i.e., right-hand side) of the rule on line 7 represents conjunction. Likewise, the :- in that rule represents implication. Thus, the rule path(X,Y) :- edge(X,Z), path(Z,Y) is the Prolog equivalent ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Concepts and Semantics of Programming Languages 1

Concepts and Semantics of Programming Languages 1

Therese Hardin, Mathieu Jaume, Francois Pessaux, Veronique Viguie Donzeau-Gouge
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9781284222739