|
Building Parsers with Java | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--sjm.engine.Variable
|
+--sjm.engine.Anonymous
An anonymous variable unifies successfully with any other term, without binding to the term.
Anonymous variables are useful for screening out unwanted terms. For example, if a program describes a marriage in terms of an id, the husband, wife, and the beginning and end dates of the marriage, its facts might look something like:
marriage(001, balthasar, grimelda, 14560512, 14880711);
// ...
marriage(257, kevin, karla, 19790623, present);
A rule that extracts just the husband from
marriage facts is:
husband(Id, Hub) :- marriage(Id, Hub, _, _, _);
The underscores in this rule represent anonymous variables.
When the rule executes, it will unify its
marriage structure with marriage
facts, without regard to the last three terms of those
facts.
Without anonymous variables, the husband rule
would need three unused variables. Note that the following
approach would fail:
husband(Id, Hub) :-
marriage(Id, Hub, Anon, Anon, Anon); // wrong
This approach, while tempting, will not work because the
variable Anon will bind to the structures it
encounters. Issued against the example program,
Anon will first bind to grimelda.
Next, Anon will attempt to bind to
14560512. This will fail, since
Anon will already be bound to
grimelda.
The essential behavior anonymous variables provide is that they unify successfully without binding.
| Fields inherited from class sjm.engine.Variable |
instantiation,
name |
| Constructor Summary | |
Anonymous()
Constructs an anonymous variable. |
|
| Method Summary | |
Term |
copyForProof(AxiomSource ignored,
Scope ignored2)
Returns this anonymous variable, which does not unify with anything and thus does not need to copy itself. |
java.lang.Object |
eval()
Return the value of this anonymous variable to use in functions; this is meaningless in logic programming, but the method returns the name of this variable. |
Unification |
unify(Structure ignored)
Returns an empty unification. |
Unification |
unify(Term ignored)
Returns an empty unification. |
Unification |
unify(Variable ignored)
Returns an empty unification. |
Unification |
variables()
Returns an empty unification. |
| Methods inherited from class sjm.engine.Variable |
definitionString,
equals,
isList,
listTailString,
toString,
unbind |
| Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Constructor Detail |
public Anonymous()
| Method Detail |
public Term copyForProof(AxiomSource ignored,
Scope ignored2)
AxiomSource - ignoredScope - ignoredpublic java.lang.Object eval()
public Unification unify(Structure ignored)
The unify methods indicate failure by
returning null. Anonymous variables succeed
without binding, so they always return empty unifications.
Structure - ignoredpublic Unification unify(Term ignored)
Term - ignoredpublic Unification unify(Variable ignored)
Variable - ignoredpublic Unification variables()
|
by Steve Metsker | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||