diff --git a/solution.pl b/solution.pl index 3a5062f..76b7af9 100644 --- a/solution.pl +++ b/solution.pl @@ -40,7 +40,13 @@ 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, Row). */ +row(Table, Row) :- + tabl(Table, Cols) -> + ( + length(Cols, L), + length(Row, L), + apply(Table, Row) + ); fail. :- dynamic rows/1. /* @@ -48,7 +54,16 @@ Displays all rows in the given table, one per line (use writeln/1). If the given table does not exist, the predicate must throw a descriptive exception. */ -/* rows(Table). */ +rows(Table) :- + \+ tabl(Table, _), + throw(table_does_not_exist(Table)), + !. + +rows(Table) :- + row(Table, Row), + writeln(Row), + fail. +rows(_). :- dynamic insert/2. /*