Fix row & rows issues when no rows

This commit is contained in:
Brieuc Dubois 2024-03-14 23:35:33 +01:00
parent 84a3075bc8
commit 1e89e0f6b7
1 changed files with 21 additions and 6 deletions

View File

@ -62,13 +62,22 @@ cols(Table, Cols) :-
Unifies Row, one result at a time, with each row in the given Table. 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. 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) :- row(Table, Row) :-
tabl(Table, Cols) -> tabl(Table, Cols),
( length(Cols, L),
length(Cols, L), length(Row, L),
length(Row, L), apply(Table, Row).
apply(Table, Row)
); throw("Table doesn't exist").
:- dynamic rows/1. :- dynamic rows/1.
/* /*
@ -81,6 +90,12 @@ rows(Table) :-
throw(table_does_not_exist(Table)), throw(table_does_not_exist(Table)),
!. !.
rows(Table) :-
tabl(Table, Cols),
length(Cols, L),
\+ current_predicate(Table/L),
!.
rows(Table) :- rows(Table) :-
row(Table, Row), row(Table, Row),
writeln(Row), writeln(Row),