Module lillib:lists

This module provides various predicates for manipulating lists, such as append and reverse.

Version

April 07, 1999

Since

July 09, 1998

Author


Contents

Predicate


Top of this page Contents Index of this package LiLFeS Documents LiLFeS Home Page Tsujii laboratory

Predicate

append/3

Formatappend(?$L1, ?$L2, ?$L3)
Arguments
?$L1list List 1
?$L2list List 2
?$L3list Concatenation of List 1 and List 2
This is true when $L3 is the combined list of the elements in $L1 and $L2 in the original orders.
 > ?- append([1, 2, 3], [4, 5], X).
  X: < 1, 2, 3, 4, 5 >

revappend/3

Formatrevappend(?$L1, ?$L2, ?$L3)
Arguments
?$L1list Reversed list
?$L2list List
?$L3list Concatenation
This is true when $L3 is the combined list of the elements in $L1 and $L2, in the reversed order as to $L1 and in the original order as to $L2.
 > ?- revappend([1, 2, 3], [4, 5], X).
  X: < 3, 2, 1, 4, 5 >

append_list/2

Formatappend_list(+$LL, -$L)
Arguments
+$LLlist of list Input lists
-$Llist Concatenation of the lists
This lets $L3 be the combined list of the elements in the elements in $LL.
 > ?- append_list([[1, 2], [3], [4, 5]],X).
  X: < 1, 2, 3, 4, 5 >

delete/3

Formatdelete(+$List1, +$Elem, -$List2)
Arguments
+$List1list input list
+$Elembot an element to be removed
-$List2list output
This removes elements $Elem from $List and returns to $List2.
 > ?- delete([1, 2, 2, 4, 5], 2, X).
  X: < 1, 4, 5 >

reverse/2

Formatreverse(?$L1, ?$L2)
Arguments
?$L1list Original ordered list
?$L2list Reversed ordered list
This is true when $L1 and $L2 have the same elements but in reversed orders each other.
 > ?- reverse([1, 2, 3, 4], X).
  X: < 4, 3, 2, 1 >

last/2

Formatlast(?$L, ?$X)
Arguments
?$Llist Input list
?$Xbot The last element of the list
This lets $X be the last element in $L.
 > ?- last([1, 2, 3, 4], X).
  X: 4

member/2

Formatmember(?$X, +$L)
Arguments
?$Xbot a list element
+$Llist a list
This is true when $X is unified with an element in $L.
 > ?- member(X, [1, 2, 3]).
  X: 1
  Enter ';' for more choices, otherwise press ENTER --> ;
  X: 2
  Enter ';' for more choices, otherwise press ENTER --> ;
  X: 3
  Enter ';' for more choices, otherwise press ENTER --> ;
  no

member_e/2

Formatmember_e(?$X, +$L)
Arguments
?$Xbot a list element
+$Llist a list
See alsomember/2
This is true when $X is equivalent to an element in $L.

member_i/2

Formatmember_i(?$X, +$L)
Arguments
?$Xbot a list element
+$Llist a list
See alsomember/2
This is true when $X is identical to an element in $L.

member_s/2

Formatmember_s(?$X, +$L)
Arguments
?$Xbot a list element
+$Llist a list
See alsomember/2
This is true when $X subsumes an element in $L.

member_sd/2

Formatmember_sd(?$X, +$L)
Arguments
?$Xbot a list element
+$Llist a list
See alsomember/2
This is true when $X is subsumed by an element in $L.

memberchk/2

Formatmemberchk(+$X, +$L)
Arguments
+$Xbot a list element
+$Llist a list
See alsomember/2
This is true when $X is unified with an element in $L. This does not succeeds more than once.
 > ?- memberchk(X, [1, 2, 3, 4]).
  X: 1

memberchk_e/2

Formatmemberchk_e(+$X, +$L)
Arguments
+$Xbot a list element
+$Llist a list
See alsomemberchk/2
This is true when $X is equivalent to an element in $L. This does not succeeds more than once.

memberchk_i/2

Formatmemberchk_i(+$X, +$L)
Arguments
+$Xbot a list element
+$Llist a list
See alsomemberchk/2
This is true when $X is identical to an element in $L. This does not succeed more than once.

memberchk_s/2

Formatmemberchk_s(+$X, +$L)
Arguments
+$Xbot a list element
+$Llist a list
See alsomemberchk/2
This is true when $X subsume an element in $L. This does not succeed more than once.

memberchk_sd/2

Formatmemberchk_sd(+$X, +$L)
Arguments
+$Xbot a list element
+$Llist a list
See alsomemberchk/2
This is true when $X is subsumed by an element in $L. This does not succeed more than once.

member_2/4

Formatmember_2(?$X1, +$L1, ?$X2, +$L2)
Arguments
?$X1bot a list element
+$L1list a list
?$X2bot a list element
+$L2list a list
See alsomember/2
This is true when $X1 and $X2 are unified with an element in $L1 and $L2 respectively. Where $X1 and $X2 are from the heads of $L1 and $L2 must be the same.
 > ?- member_2(X, [1, 2], Y, [4, 5]).
  X: 1
  Y: 4
  Enter ';' for more choices, otherwise press ENTER --> ;
  X: 2
  Y: 5
  Enter ';' for more choices, otherwise press ENTER --> ;
  no

fast_member/2

Formatfast_member(+$L, ?$X)
Arguments
+$Llist a list
?$Xbot a list element
See alsomember/2
This is true when $X is unified with an element in $L. This is the same as 'member', but the order of the arguments is changed and this is faster.
 > ?- fast_member([1, 2, 3], X).
  X: 1
  Enter ';' for more choices, otherwise press ENTER --> ;
  X: 2
  Enter ';' for more choices, otherwise press ENTER --> ;
  X: 3
  Enter ';' for more choices, otherwise press ENTER --> ;
  no

fast_member_2/4

Formatfast_member_2(+$L1, ?$X1, +$L2, ?$X2)
Arguments
+$L1list list
?$X1bot list element
+$L2list list
?$X2bot list element
See alsomember_2/4 fast_member/2
This is true when $X1 and $X2 are unified with elements in $L1 and $L2 respectively. Where $X1 and $X2 are from the heads of $L1 and $L2 must be the same. This is the same as 'member_2', but the order of the arguments is changed and this is faster.
 > ?- fast_member_2([1, 2], X, [3, 4], Y).
  X: 1
  Y: 3
  Enter ';' for more choices, otherwise press ENTER --> ;
  X: 2
  Y: 4
  Enter ';' for more choices, otherwise press ENTER --> ;
  no

assoc/3

Formatassoc(+$X, +$L, -$Y)
Arguments
+$Xbot key
+$Llist of ',/2' association list
-$Ybot data
This lets $Y be the second element of the pair whose first element is unified with $X. The 2-element pair (',/2') is the first proper one in $L. This does not succeed more than once.
 > ?- assoc(1, [(1, "a"), (2, "b")], X).
  X: "a"

assoc_e/3

Formatassoc_e(+$X, +$L, -$Y)
Arguments
+$Xbot key
+$Llist of ',/2' association list
-$Ybot data
See alsoassoc/3
This lets $Y be the second element of the pair whose first element is equivalent to $X. The 2-element pair (',/2') is the first proper one in $L. This does not succeed more than once.

assoc_i/3

Formatassoc_i(+$X, +$L, -$Y)
Arguments
+$Xbot key
+$Llist of ',/2' association list
-$Ybot data
See alsoassoc/3
This lets $Y be the second element of the pair whose first element is identical to $X. The 2-element pair (',/2') is the first proper one in $L. This does not succeed more than once.

remove_duplicates/2

Formatremove_duplicates(+$L1, -$L2)
Arguments
+$L1list an original list
-$L2list output list
This lets $L2 be the result of removing all equivalent duplicate elements in $L1.
 > ?- remove_duplicates([1, 2, 3, 2, 4], X).
  X: < 1, 3, 2, 4 >

listcommon/3

Formatlistcommon(+$L1, +$L2, -$L3)
Arguments
+$L1list list 1
+$L2list list 2
-$L3list common part of the lists
AuthorNISHIDA Kenji (nishiken@is.s.u-tokyo.ac.jp)
This lets $L3 be a list of all the elements that have equivalent elements both in $L1 and in $L2.
 > ?- listcommon([1, 2, 3, 4], [5, 4, 3], X).
  X: < 3, 4 >

flatten_list/2

Formatflatten_list(+$L1, -$L2)
Arguments
+$L1list input list
-$L2list output list
This lets $L2 be a flattened list of $L1.
 > ?- flatten_list([1, [2, [3, 4], 5]], X).
  X: < 1, 2, 3, 4, 5 >

make_n_list/3

Formatmake_n_list(+$N, +$X, -$L)
Arguments
+$Ninteger (>= 0) length of a list
+$Xbot a list element
-$Llist output
This lets $L be a list whose length is $N and all the elements are equivalent to $X.
 > ?- make_n_list(5, "hoge", X).
  X: < "hoge", "hoge", "hoge", "hoge", "hoge" >

make_num_list/3

Formatmake_num_list(+$FROM, +$BEFORE, -$RESULT)
Arguments
+$FROMinteger a start of a list
+$BEFOREinteger an end of the list
-$RESULTlist of integers output
This lets $RESULT be a list whose elements are the integers from $FROM before $BEFORE.
 > ?- make_num_list(2, 5, X).
  X: < 2, 3, 4 >

length/2

Formatlength(+$L, -$N)
Arguments
+$Llist input list
-$Ninteger length of the list
This lets $N be the length of $L.
 > ?- length([3, 3, 3, 3], X).
  X: 4

nth_elem/3

Formatnth_elem(+$LIST, +$N, -$ELEM)
Arguments
+$LISTlist a list
+$Ninteger index
-$ELEMbot an element of the list
This returns $Nth element of the list $LIST as $ELEM.
 > ?- nth([2, 4, 6, 8], 2, X).
  X: 6

set_difference/3

Formatset_difference(+$Set1, +$Set2, -$Diff)
Arguments
+$Set1list Set 1
+$Set2list Set 2
This returns the elements of $Set1 not included in $Set2.
 > ?- set_difference([1, 2, 3, 4], [6, 4, 2], X).
  X: < 1, 3 >

set_difference_e/3

Formatset_difference_e(+$Set1, +$Set2, -$Diff)
Arguments
+$Set1list Set 1
+$Set2list Set 2
See alsoset_difference/3
This returns the elements of $Set1 not included in $Set2.

set_difference_i/3

Formatset_difference_i(+$Set1, +$Set2, -$Diff)
Arguments
+$Set1list Set 1
+$Set2list Set 2
See alsoset_difference/3
This returns the elements of $Set1 not included in $Set2.

input_list/2

Formatinput_list(+$STRING, -$LIST)
Arguments
+$STRINGstring a lisp list
-$LISTlist a lilfes list
See alsooutput_list/2
Convert a string into a lilfes list

output_list/2

Formatoutput_list(+$LIST, -$STRING)
Arguments
+$LISTlist a lilfes list
-$STRINGstring a lisp list
See alsolisp_to_lilfes/2
Convert a lilfes list into a lisp list

dlength/3

Formatdlength(+Head, +Tail, -N)
Arguments
+Headlist
+Taillist
-Ninteger
Returns the length of the difference list between Head and Tail.

dmember/3

Formatdmember(+LHead, +LTail, ?E)
Arguments
+LHeadhead of the difference list
+LTailtail (end) of the difference list
?Ethe element to search for
as with member, but searches in a difference list given by 'LHead' and 'LTail'

dmember_2/5

Formatdmember_2(+L1Head, +L1Tail, ?E1, +L2, ?E2)
Arguments
+L1Headhead of the first list (difference list)
+L1Tailtail (end) of the first list
?E1the element to search for in the first list
+L2second list
?E2the element to search for in the second list
as 'fast_member_2', but the first list is considered a difference list It is not necessary to give the 2nd list as difference list as well, as both lists are processed in tandem.

Top of this page Contents Index of this package LiLFeS Documents LiLFeS Home Page Tsujii laboratory

Send comments to:
MITSUISHI Yutaka (mitsuisi@is.s.u-tokyo.ac.jp)

This document is automatically created by lildoc on Fri Sep 24 14:13:58 2004