sleep.interfaces
Interface Predicate
- BasicNumbers, BasicUtilities
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.
boolean | decide(String predicateName, ScriptInstance anInstance, Stack passedInTerms) - decides the truthfulness of the proposition predicateName applied to the passedInTerms.
|
decide
public boolean decide(String predicateName,
ScriptInstance anInstance,
Stack passedInTerms)
decides the truthfulness of the proposition predicateName applied to the passedInTerms.
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]
- a boolean, in the case of a predicate == and the terms [3, 4] we know 3 == 4 is false so return false.