diff --git a/solution.pl b/solution.pl index 887296f..b6c243c 100644 --- a/solution.pl +++ b/solution.pl @@ -61,7 +61,15 @@ exception. If the row does not have as many elements as the number of columns in the table, the predicate must throw a descriptive exception. */ -/* insert(Table, Row). */ +insert(Table, Row) :- + (tabl(Table, Cols) -> + (length(Row, L1), length(Cols, L2), L1 =:= L2 -> + Term =.. [Table | Row], + assertz(Term); + throw("Row doesn't have as many elements as the number of columns in the table") + ); + throw("Table doesn't exist") + ). :- dynamic drop/1. /*