From 843d2d231b54da7b6f1cd2dce6924ac8fa0a239f Mon Sep 17 00:00:00 2001 From: SmitSanghvi94 <101258379+SmitSanghvi94@users.noreply.github.com> Date: Tue, 11 Jul 2023 19:14:05 +0530 Subject: [PATCH] Update practical-session.pl Changed the solution as not/1 predicate has not been introduced yet and I think should not be used. --- chapter-06/practical-session.pl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/chapter-06/practical-session.pl b/chapter-06/practical-session.pl index 235d23f..01cbd25 100644 --- a/chapter-06/practical-session.pl +++ b/chapter-06/practical-session.pl @@ -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