Move deletion logic to delete/2

This commit is contained in:
Brieuc Dubois 2024-03-14 18:11:33 +01:00
parent d5351f3dee
commit eeaba5ee46
1 changed files with 8 additions and 6 deletions

View File

@ -131,16 +131,18 @@ prompt, but which may include selectors. Selectors are terms of the form
delete(Table, Conds) :- delete(Table, Conds) :-
(tabl(Table, _) -> (tabl(Table, _) ->
row(Table, Row), row(Table, Row),
does_match(Conds, Table, Row) does_match(Conds, Table, Row),
Term =.. [Table | Row],
retract(Term),
fail
; ;
throw("Table doesn't exist") throw("Table doesn't exist")
); true. ).
delete(_, _).
does_match([], Table, Row) :- does_match([], _, _) :- !.
Term =.. [Table | Row],
retract(Term),
fail.
does_match([Cond|Rest], Table, Row) :- does_match([Cond|Rest], Table, Row) :-
% Extract the operator, field and value from the condition % Extract the operator, field and value from the condition