diff --git a/solution.pl b/solution.pl index d91821c..a70ba03 100644 --- a/solution.pl +++ b/solution.pl @@ -62,13 +62,22 @@ cols(Table, Cols) :- Unifies Row, one result at a time, with each row in the given Table. If the given table does not exist, the predicate should fail. */ +row(Table, _) :- + \+ tabl(Table, _), + throw("Table doesn't exist"), + !. + +row(Table, _) :- + tabl(Table, Cols), + length(Cols, L), + \+ current_predicate(Table/L), + !. + row(Table, Row) :- - tabl(Table, Cols) -> - ( - length(Cols, L), - length(Row, L), - apply(Table, Row) - ); throw("Table doesn't exist"). + tabl(Table, Cols), + length(Cols, L), + length(Row, L), + apply(Table, Row). :- dynamic rows/1. /* @@ -81,6 +90,12 @@ rows(Table) :- throw(table_does_not_exist(Table)), !. +rows(Table) :- + tabl(Table, Cols), + length(Cols, L), + \+ current_predicate(Table/L), + !. + rows(Table) :- row(Table, Row), writeln(Row),