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.
|
||||
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) ->
|
||||
(
|
||||
length(Cols, L),
|
||||
length(Row, L),
|
||||
apply(Table, Row)
|
||||
); throw("Table doesn't exist").
|
||||
tabl(Table, Cols),
|
||||
length(Cols, L),
|
||||
length(Row, L),
|
||||
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),
|
||||
|
|
Loading…
Reference in New Issue