Interface Term

    • Method Detail

      • getName

        java.lang.String getName()
        Returns a string representation of this term.

        Exact value returned will vary by TermType.

        Returns:
        a string representation of this term
      • getArgs

        Term[] getArgs()
        Returns an array of this terms's arguments.

        Note: for performance reasons the array returned is the same array used internally be the term instance so be careful not to alter the array returned as changes will be reflected in the original term.

        Returns:
        array of this terms's arguments
        See Also:
        getArgument(int)
      • getNumberOfArguments

        int getNumberOfArguments()
        Returns the number of arguments in this term.
        Returns:
        number of arguments in this term
      • getArgument

        Term getArgument​(int index)
        Returns the term at the specified position in this term's arguments.
        Parameters:
        index - index of the argument to return
        Returns:
        the term at the specified position in this term's arguments
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getNumberOfArguments())
      • copy

        Term copy​(java.util.Map<Variable,​Variable> sharedVariables)
        Returns a copy of this term.

        The returned copy will share any immutable terms contained in this term. The returned copy will contain new instances for any Variables contained in this term. The sharedVariables parameter keeps track of which Variables have already been copied.

        Parameters:
        sharedVariables - keeps track of which Variables have already been copied (key = original version, value = version used in copy)
        Returns:
        a copy of this term
      • getBound

        default Term getBound()
        Returns the term this object is bound to.

        For anything other than a Variable this method will return this. TODO think of a better name and explanation.

      • getTerm

        Term getTerm()
        Returns the current instantiated state of this term.

        Returns a representation of this term with all instantiated Variables replaced with the terms they are instantiated with.

        Returns:
        a representation of this term with all instantiated Variables replaced with the terms they are instantiated with.
      • unify

        boolean unify​(Term t)
        Attempts to unify this term to the specified term.

        The rules for deciding if two terms are unifiable are as follows:

        • An uninstantiated Variable will unify with any term. As a result the Variable will become instantiated to the other term. The instantiaton will be undone when backtrack() is next called on the Variable
        • Non-variable terms will unify with other terms that are of the same TermType and have the same value. The exact meaning of "having the same value" will vary between term types but will include that the two terms being unified have the same number of arguments and that all of their corresponding arguments unify.
        Note: can leave things in "half-state" on failure as neither List or Predicate backtrack earlier args.
        Parameters:
        t - the term to unify this term against
        Returns:
        true if the attempt to unify this term to the given term was successful
        See Also:
        backtrack()
      • backtrack

        void backtrack()
        Reverts this term back to its original state prior to any unifications.

        Makes all Variables that this term consists of uninstantiated.

        See Also:
        unify(Term)
      • isImmutable

        boolean isImmutable()
        Returns true is this term is immutable.

        A term is considered immutable if its value will never change as a result of executing its unify(Term) or backtrack() methods. A term will not be considered immutable if it is a Variable or any of its arguments are not immutable.

        Returns:
        true is this term is immutable