12.4. Unification

Suppose that you would like to be able to match a structure such as:

city(Name, Altitude) 

with a structure such as:

city(denver, 5280) 

so that you can extract a structure's data into variables. Logic engines provide just this kind of matching in a behavior called unification. Unification lets a variable bind to a value. It also allows entire structures to bind, with all the terms in a structure binding to their counterparts in another structure. For example, if you ask the two structures here to unify, the variables Name and Altitude will unify with denver and 5280, as the following program shows:

 package sjm.examples.engine; import sjm.engine.*; /** * Show two structures unifying. */ public class ShowStructureUnification ...

Get Building Parsers with Java™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.