First answers

This commit is contained in:
Brieuc Dubois 2024-03-02 00:16:47 +01:00
parent 39593bc48b
commit dc73df33b0
1 changed files with 6 additions and 4 deletions

View File

@ -3,13 +3,13 @@
Prints the names of all existing tables, one per line (use writeln/1). Prints the names of all existing tables, one per line (use writeln/1).
A table name is always an atom. A table name is always an atom.
*/ */
tables. tables :- tabl(X, _), writeln(X).
:- dynamic tables/1. :- dynamic tables/1.
/* /*
Unify Tables with a list of the names of all existing tables. Unify Tables with a list of the names of all existing tables.
*/ */
tables(Tables). tables(Tables) :- findall(X, tabl(X, _), Tables).
:- dynamic create_table/2. :- dynamic create_table/2.
/* /*
@ -20,7 +20,9 @@ If a table with the given name already exists, the predicate must throw a
descriptive exception (use throw/1). descriptive exception (use throw/1).
All exceptions must have a descriptive error message. All exceptions must have a descriptive error message.
*/ */
create_table(Table, Cols). create_table(Table, Cols) :-
(tabl(Table, _) -> throw("Table already exists"));
assertz(tabl(Table, Cols)).
:- dynamic cols/2. :- dynamic cols/2.
/* /*