Fix row & rows issues when no rows
This commit is contained in:
parent
84a3075bc8
commit
1e89e0f6b7
27
solution.pl
27
solution.pl
|
@ -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),
|
||||||
|
|
Loading…
Reference in New Issue