From eeaba5ee465417cebbe7a40b77aa5017b62acd4f Mon Sep 17 00:00:00 2001 From: Brieuc Dubois Date: Thu, 14 Mar 2024 18:11:33 +0100 Subject: [PATCH] Move deletion logic to delete/2 --- solution.pl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/solution.pl b/solution.pl index 7a98b6a..509fdaa 100644 --- a/solution.pl +++ b/solution.pl @@ -131,16 +131,18 @@ prompt, but which may include selectors. Selectors are terms of the form delete(Table, Conds) :- (tabl(Table, _) -> row(Table, Row), - does_match(Conds, Table, Row) + does_match(Conds, Table, Row), + Term =.. [Table | Row], + retract(Term), + fail ; throw("Table doesn't exist") - ); true. + ). + +delete(_, _). -does_match([], Table, Row) :- - Term =.. [Table | Row], - retract(Term), - fail. +does_match([], _, _) :- !. does_match([Cond|Rest], Table, Row) :- % Extract the operator, field and value from the condition