From 4ec8cba12bda69204248e4c79d81197ae4318a24 Mon Sep 17 00:00:00 2001 From: Brieuc Dubois Date: Sun, 10 Mar 2024 13:14:13 +0100 Subject: [PATCH] insert/2 --- solution.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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. /*