This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/pl/lists.yap

43 lines
1.2 KiB
Plaintext
Raw Normal View History

2013-11-26 09:40:00 +00:00
2014-04-09 12:39:29 +01:00
:- system_module( '$_lists', [], []).
2013-11-26 09:53:04 +00:00
:- '$set_yap_flags'(11,1). % source.
2013-11-26 09:40:00 +00:00
% memberchk(+Element, +Set)
% means the same thing, but may only be used to test whether a known
% Element occurs in a known Set. In return for this limited use, it
% is more efficient when it is applicable.
lists:memberchk(X,[X|_]) :- !.
lists:memberchk(X,[_|L]) :-
lists:memberchk(X,L).
% member(?Element, ?Set)
% is true when Set is a list, and Element occurs in it. It may be used
% to test for an element or to enumerate all the elements by backtracking.
% Indeed, it may be used to generate the Set!
lists:member(X,[X|_]).
lists:member(X,[_|L]) :-
lists:member(X,L).
lists:append([], L, L).
lists:append([H|T], L, [H|R]) :-
lists:append(T, L, R).
2013-11-26 09:53:04 +00:00
:- '$set_yap_flags'(11,0). % :- no_source.
2014-04-09 12:39:29 +01:00
% lists:delete(List, Elem, Residue)
% is true when List is a list, in which Elem may or may not occur, and
% Residue is a copy of List with all elements identical to Elem lists:deleted.
lists:delete([], _, []).
lists:delete([Head|List], Elem, Residue) :-
Head == Elem, !,
lists:delete(List, Elem, Residue).
lists:delete([Head|List], Elem, [Head|Residue]) :-
lists:delete(List, Elem, Residue).