diff --git a/solution.pl b/solution.pl index 14223f9..58c83e2 100644 --- a/solution.pl +++ b/solution.pl @@ -159,19 +159,28 @@ delete(Table, Conds) :- ). -does_match([], _, Row) :- !. + does_match([], _, _) :- !. -does_match([Cond|Rest], Table, Row) :- - % Extract the operator, field and value from the condition - Cond =.. [Operator | T], - [+F, S] = T, - - tabl(Table, Cols), - member(F, Cols), - nth0(Index, Cols, F), - nth0(Index, Row, Value), - apply(Operator, [Value, S]), - does_match(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) ).