public interface PrologList extends PrologTerm, Iterable<PrologTerm>
Represent prolog list compound term. List are an special compound term that have like functor a dot (.) and arity equals 2. Prolog list are recursively defined. The first item in the list is referred like list head and the second item list tail. The list tail can be another list that contains head and tail. An special list case is the empty list denoted by no items brackets ([]). The arity for this empty list is zero.
The Prolog Provider is the mechanism to create a new Prolog structures
invoking PrologProvider.newList()
for empty list or
PrologProvider.newList(PrologTerm)
for one item list or
PrologProvider.newList(PrologTerm[])
for many items.
Two list are equals if and only if are list and have equals arguments. List terms unify only with the same arguments list, with free variable or with lists where your arguments unify.
PrologList empty = provider.newList();
PrologInteger one = provider.newInteger(1); PrologInteger two = provider.newInteger(2); PrologInteger three = provider.newInteger(3); PrologList list = provider.newList(new PrologTerm[] { one, two, three });PrologList implement
Iterable
interface to be used in for each
sentence iterating over every element present in the list.
for (PrologTerm prologTerm : list) { System.out.println(prologTerm); }
Iterator<PrologTerm> i = list.iterator(); while (i.hasNext()) { PrologTerm prologTerm = i.next(); System.out.println(prologTerm); }
for (Iterator<PrologTerm> i = list.iterator(); i.hasNext();) { PrologTerm prologTerm = i.next(); System.out.println(prologTerm); }
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the current list removing all contained prolog term.
|
PrologTerm |
getHead()
Return the head term of the current list if the current list have at least
one element.
|
PrologTerm |
getTail()
Return the tail term of the current list if the current list have tail.
|
boolean |
isEmpty()
Return true if the current list don't have any elements, false in other case.
|
int |
size()
Returns the number of elements in this list.
|
cast, getArgument, getArguments, getArity, getFunctor, getIndicator, getObject, getProvider, getTerm, getType, hasIndicator, isAtom, isAtomic, isClass, isCompound, isDouble, isEmptyList, isEntry, isEvaluable, isFalseType, isField, isFloat, isInteger, isList, isLong, isMap, isMixin, isNil, isNullType, isNumber, isObjectType, isParameter, isReference, isResult, isStructure, isTrueType, isVariable, isVariableBound, isVariableNotBound, isVoidType, match, unify
compareTo
isClause, isTerm
forEach, iterator, spliterator
PrologTerm getHead()
Prolog
empty list term,
the result for invoke get head is the empty list term properly.PrologTerm getTail()
boolean isEmpty()
return #size()==0
void clear()
int size()
Copyright © 2020–2024 Prolobjectlink Project. All rights reserved.