improved does_match by Brieuc
This commit is contained in:
parent
d40cbb70df
commit
b6df1b1ade
16
solution.pl
16
solution.pl
|
@ -159,18 +159,27 @@ delete(Table, Conds) :-
|
|||
).
|
||||
|
||||
|
||||
does_match([], _, Row) :- !.
|
||||
does_match([], _, _) :- !.
|
||||
|
||||
does_match([Cond|Rest], Table, Row) :-
|
||||
does_match([Cond|Rest], Table, Row) :-
|
||||
% Extract the operator, field and value from the condition
|
||||
Cond =.. [Operator | T],
|
||||
[+F, S] = T,
|
||||
|
||||
% Get the columns of the table
|
||||
tabl(Table, Cols),
|
||||
|
||||
% Get the index of the field in the columns
|
||||
member(F, Cols),
|
||||
nth0(Index, Cols, F),
|
||||
|
||||
% Get the value of the field in the row
|
||||
nth0(Index, Row, Value),
|
||||
|
||||
% Apply the operator to the value and the selector
|
||||
apply(Operator, [Value, S]),
|
||||
|
||||
% Check the next condition
|
||||
does_match(Rest, Table, Row).
|
||||
|
||||
:- dynamic selec/4.
|
||||
|
@ -229,8 +238,7 @@ selector(Row, Cols, [+Selector|Selectors], AccCols, AccVals, ColumnNames, Column
|
|||
%go to next column tho evaluate
|
||||
selector(Row, Cols, Selectors, [Selector|AccCols], [Value|AccVals], ColumnNames, ColumnValue)
|
||||
;
|
||||
string_concat(Selector, " isn't a column of table ", X),
|
||||
string_concat(X, Table, Error),
|
||||
string_concat(Selector, " isn't a column of table ", Error),
|
||||
throw(Error)
|
||||
).
|
||||
|
||||
|
|
Loading…
Reference in New Issue