Package jason.stdlib

Class prefix

All Implemented Interfaces:
InternalAction, Serializable

@Manual(literal=".prefix(prefix,list)", hint="checks if some list is a prefix of other list, backtracking all free variables", argsHint={"the prefix to be checked","the list where the prefix is from"}, argsType={"list","list"}, examples={".prefix([a],[a,b,c]): true",".prefix([a,b],[a,b,c]): true",".prefix([b,c],[a,b,c]): false",".prefix(X,[a,b,c]): unifies X with any prefix of the list, i.e., [a,b,c], [a,b], [a], and [] in this order"}, seeAlso={"jason.stdlib.concat","jason.stdlib.length","jason.stdlib.sublist","jason.stdlib.sort","jason.stdlib.shuffle","jason.stdlib.suffix","jason.stdlib.nth","jason.stdlib.max","jason.stdlib.min","jason.stdlib.reverse","jason.stdlib.difference","jason.stdlib.intersection","jason.stdlib.union"}) public class prefix extends DefaultInternalAction

Internal action: .prefix(P,L).

Description: checks if some list/string P is a prefix of list/stringL. If P has free variables, this internal action backtracks all possible values for P.

Parameters:

  • +/- prefix (list or string): the prefix to be checked.
  • + list (list or string): the list where the prefix is from.

Examples:

  • .prefix([a],[a,b,c]): true.
  • .prefix([a,b],[a,b,c]): true.
  • .prefix([b,c],[a,b,c]): false.
  • .prefix(X,[a,b,c]): unifies X with any prefix of the list, i.e., [a,b,c], [a,b], [a], and [] in this order; note that this is different from what its usual implementation in logic programming would result, where the various prefixes are returned in increasing lengths instead.
  • .prefix("a","abc"): true.
  • .prefix("bc","abc"): false.
  • .prefix(X,"abc"): unifies X with any prefix of the string, i.e., "abc", "ab", "a", and "" in this order.
See Also: