Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update practical-session.pl #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions chapter-06/practical-session.pl
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,15 @@
%% base case
accSet([],L,L).
%% inductive case
accSet([X|Inlist], AccList, Outlist) :-
not(member(X,AccList)),
accSet(Inlist,[X|AccList],Outlist).
accSet([X|Inlist], AccList, Outlist) :-
member(X,AccList),
accSet(Inlist,AccList,Outlist).
accSet([X|Inlist], AccList, Outlist) :-
accSet(Inlist,[X|AccList],Outlist).
%% main
set(Inlist,Outlist) :-
rev(TempOutlist, Outlist),
accSet(Inlist,[],TempOutlist).
accSet(Inlist,[],TempOutlist),
rev(TempOutlist, Outlist).

%% 3. We `flatten' a list by removing all the square brackets around any lists it
%% contains as elements, and around any lists that its elements contain as
Expand Down