Class List

java.lang.Object
org.projog.core.term.List
All Implemented Interfaces:
Term

public final class List extends Object implements Term
Represents a data structure with two Terms - a head and a tail.

The head and tail can be any Terms - including other Lists. By having a List with a List as its tail it is possible to represent an ordered sequence of Terms of any length. The end of an ordered sequence of Terms is normally represented as a tail having the value of an EmptyList.

See Also:
  • Constructor Details

    • List

      public List(Term head, Term tail)
      Creates a new list with the specified head and tail.

      Consider using ListFactory rather than calling directly.

      Parameters:
      head - the head of the new list
      tail - the tail of the new list
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface Term
      Returns:
      ListFactory.LIST_PREDICATE_NAME
    • getNumberOfArguments

      public int getNumberOfArguments()
      Description copied from interface: Term
      Returns the number of arguments in this term.
      Specified by:
      getNumberOfArguments in interface Term
      Returns:
      number of arguments in this term
    • firstArgument

      public Term firstArgument()
      Specified by:
      firstArgument in interface Term
    • secondArgument

      public Term secondArgument()
      Specified by:
      secondArgument in interface Term
    • getArgument

      public Term getArgument(int index)
      Description copied from interface: Term
      Returns the term at the specified position in this term's arguments.
      Specified by:
      getArgument in interface Term
      Parameters:
      index - index of the argument to return
      Returns:
      the term at the specified position in this term's arguments
    • getType

      public TermType getType()
      Returns TermType.LIST.
      Specified by:
      getType in interface Term
      Returns:
      TermType.LIST
    • isImmutable

      public boolean isImmutable()
      Description copied from interface: Term
      Returns true is this term is immutable.

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

      Specified by:
      isImmutable in interface Term
      Returns:
      true is this term is immutable
    • getTerm

      public List getTerm()
      Description copied from interface: Term
      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.

      Specified by:
      getTerm in interface Term
      Returns:
      a representation of this term with all instantiated Variables replaced with the terms they are instantiated with.
    • copy

      public List copy(Map<Variable,Term> sharedVariables)
      Description copied from interface: Term
      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.

      Specified by:
      copy in interface Term
      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
    • unify

      public boolean unify(Term t1)
      Description copied from interface: Term
      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 Term.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.
      Specified by:
      unify in interface Term
      Parameters:
      t1 - 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

      public void backtrack()
      Description copied from interface: Term
      Reverts this term back to its original state prior to any unifications.

      Makes all Variables that this term consists of uninstantiated.

      Specified by:
      backtrack in interface Term
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object