O'Reilly logo

Building Parsers with Java™ by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required