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	    sublist/2,			% ?Sub, +List
   40
   41	    % The following predicates are built-in on SWI.
   42	    % We re-export them here to avoid warnings
   43	    % when SICStus code explicitly imports them from library(lists).
   44	    is_list/1,			% +Term
   45	    memberchk/2			% +Element, +List
   46	  ]).   47:- reexport('../../lists',
   48	    [ append/3,
   49	      delete/3,
   50	      last/2,
   51	      max_list/2,
   52	      member/2,
   53	      min_list/2,
   54	      nextto/3,
   55	      nth0/3,
   56	      nth0/4,
   57	      permutation/2,
   58	      prefix/2,
   59	      reverse/2,
   60	      same_length/2,
   61	      select/3,
   62	      sum_list/2
   63	    ]).   64
   65:- multifile sicstus:rename_module/2.   66
   67sicstus: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 as List with all value that are identical (==) to OldElem replaced by NewList.
   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).
 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.
  132sublist(Sub, List) :-
  133	sublist_(List, Sub).
  134
  135sublist_([], []).
  136sublist_([H|T], Sub) :-
  137	sublist__(T, H, Sub).
  138
  139sublist__([], H, [H]).
  140sublist__([], _, []).
  141sublist__([H|T], X, [X|Sub]) :-
  142	sublist__(T, H, Sub).
  143sublist__([H|T], _, Sub) :-
  144	sublist__(T, H, Sub)