sleep.interfaces
Interface Predicate


public interface Predicate

A predicate is an operator used inside of comparisons. Comparisons are used in if statements and loop constructs. Sleep supports two types of predicates. A unary predicate which takes one argument. The other type is a binary (normal) predicate which takes two arguments. In the example comparison a == b, a is the left hand side, b is the right hand side, and == is the predicate. Predicate bridges are used to add new predicates to the language.

To install a predicate into a script environment:

 ScriptInstance script;           // assume
 Predicate      myPredicateBridge; // assume
 
 Hashtable environment = script.getScriptEnvironment().getEnvironment();
 environment.put("isPredicate", myPredicateBridge);
 

In the above code snippet the script environment is extracted from the script instance class. A binary predicate can have any name. A unary predicate always begins with the - minus symbol. "isin" would be considered a binary predicate where as "-isletter" would be considered a unary predicate.


Method Summary
 boolean decide(java.lang.String predicateName, ScriptInstance anInstance, java.util.Stack passedInTerms)
          decides the truthfulness of the proposition predicateName applied to the passedInTerms.
 

Method Detail

decide

boolean decide(java.lang.String predicateName,
               ScriptInstance anInstance,
               java.util.Stack passedInTerms)
decides the truthfulness of the proposition predicateName applied to the passedInTerms.

Parameters:
predicateName - a predicate i.e. ==
anInstance - an instance of the script asking about this predicate.
passedInTerms - a stack of terms i.e. [3, 4]. These arguments are passed in REVERSE ORDER i.e. [right hand side, left hand side]
Returns:
a boolean, in the case of a predicate == and the terms [3, 4] we know 3 == 4 is false so return false.