View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2010-2011, University of Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(sicstus_lists,
   36	  [ substitute/4,		% +Elem, +List, +NewElem, -List
   37	    nth/3,			% ?N, ?List, ?Element
   38	    nth/4,			% ?N, ?List, ?Element, ?Rest
   39	    same_length/3,		% ?List1, ?List2, ?Length
   40	    sublist/2,			% ?Sub, +List
   41	    suffix/2,			% ?Suffix, ?List
   42
   43	    % The following predicates are built-in on SWI.
   44	    % We re-export them here to avoid warnings
   45	    % when SICStus code explicitly imports them from library(lists).
   46	    is_list/1,			% +Term
   47	    memberchk/2			% +Element, +List
   48	  ]).   49:- reexport('../../lists',
   50	    [ append/3,
   51	      delete/3,
   52	      last/2,
   53	      max_list/2,
   54	      member/2,
   55	      min_list/2,
   56	      nextto/3,
   57	      nth0/3,
   58	      nth0/4,
   59	      permutation/2,
   60	      prefix/2,
   61	      reverse/2,
   62	      same_length/2,
   63	      select/3,
   64	      sum_list/2
   65	    ]).   66
   67:- multifile sicstus:rename_module/2.   68
   69sicstus:rename_module(lists, sicstus_lists).

SICStus 3-compatible library(lists).

See also
- https://sicstus.sics.se/sicstus/docs/3.12.11/html/sicstus/Lists.html */
To be done
- This library is incomplete. As of SICStus 3.12.11, the following predicates are missing:
 substitute(+OldElem, +List, +NewElem, -NewList) is det
NewList is List with all values that are identical (==) to OldElem replaced by NewElem.
   88substitute(Old, List, New, NewList) :-
   89	substitute_(List, Old, New, NewList).
   90
   91substitute_([], _, _, []).
   92substitute_([O|T0], Old, New, [V|T]) :-
   93	(   Old == O
   94	->  V = New
   95	;   V = O
   96	),
   97	substitute_(T0, Old, New, T).
 nth(?Index, ?List, ?Element) is nondet
True if Element is the N-th element in List. Counting starts at 1.
deprecated
- use nth1/3.
  107nth(Index, List, Element) :-
  108	nth1(Index, List, Element).
 nth(?Index, ?List, ?Element, ?Rest) is nondet
True if Element is the N-th element in List and Rest is the remainder (as if by select/3) of List. Counting starts at 1.
deprecated
- use nth1/4.
  118nth(Index, List, Element, Rest) :-
  119	nth1(Index, List, Element, Rest).
 same_length(?List1, ?List2, ?Length) is nondet
True if List1 and List2 both have length Length.
  126same_length(List1, List2, Length) :-
  127	(   var(List1)
  128	->  length(List2, Length),
  129	    length(List1, Length)
  130	;   length(List1, Length),
  131	    length(List2, Length)
  132	).
 sublist(?Sub, +List)
True when all members of Sub are members of List in the same order.
Compatibility
- sicstus. The order of generating sublists differs.
- This predicate is known in many Prolog implementations, but the semantics differ. E.g. In YAP it is a continuous sub-list.
  145sublist(Sub, List) :-
  146	sublist_(List, Sub).
  147
  148sublist_([], []).
  149sublist_([H|T], Sub) :-
  150	sublist__(T, H, Sub).
  151
  152sublist__([], H, [H]).
  153sublist__([], _, []).
  154sublist__([H|T], X, [X|Sub]) :-
  155	sublist__(T, H, Sub).
  156sublist__([H|T], _, Sub) :-
  157	sublist__(T, H, Sub).
 suffix(?Suffix, ?List) is nondet
True if Suffix is a suffix of List. Not the same as suffix/2 in SICStus 4 - the arguments are reversed!
  165suffix(List, List).
  166suffix(Suffix, [_|Tail]) :-
  167	suffix(Suffix, Tail)