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.
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) :-
tabl(Table, Cols) ->
(
tabl(Table, Cols),
length(Cols, L),
length(Row, L),
apply(Table, Row)
); throw("Table doesn't exist").
apply(Table, Row).
:- dynamic rows/1.
/*
@ -81,6 +90,12 @@ rows(Table) :-
throw(table_does_not_exist(Table)),
!.
rows(Table) :-
tabl(Table, Cols),
length(Cols, L),
\+ current_predicate(Table/L),
!.
rows(Table) :-
row(Table, Row),
writeln(Row),