From 59ea540c458510ac0b3688addec1e16931f55f50 Mon Sep 17 00:00:00 2001 From: Brieuc Dubois Date: Wed, 13 Mar 2024 09:49:08 +0100 Subject: [PATCH] row/2, rows/1 --- solution.pl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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. /*