% Schema %------- % * Each predicate (relation) is named. % * Each column is (optionally) named. % * Each column is assigned a data type. % * Datatypes are: integer, real, string, any. % * Columns of type any can contain complex terms (functors). database({city(Name:string, State:string, Population:integer), distance(City1:string, City2:string, Distance:real) }). %Derivated predicates and rules %------------------------------ % % * New (or derived) predicates are defined by rules. % % * Example: derive the city in Texas with more than 400,000 people % % lt_city(C, Pop) <- city(C, 'Texas', Pop), Pop > 400000. % % * Rules have a purely declarative role, similar to virtual views in % relational databases % % * Queries have an imperative role: when the query is executed then the % results tha satisfy the query are returned % % * Example: List all cities in Texas with where the population exceeds % 400,000. % % query lt_city(C, Pop) % % This query will return: % % lt_city('Huston', 3000000) % lt_city('Dallas', 2000000) % lt_city('Austin', 750000) % lt_city('San Antonio', 1500000) % % * But queries without variables (aka closed queries) return a yes/no answer % (no in this case since Austin does not have 2,000,000 inhabitants) % %The command % % query lt_city('Austin', 2000000) % %will actually be used in the regular interface, while in the Java interface %the user will select an item from the menu. lt_city(C, Pop) <- city(C, 'Texas', Pop), Pop > 400000. export lt_city(X, Y). % X is given and Y is expected. export lt_city($X, Y). % X is expected and Y is given. export lt_city(X, $Y). % Both X and Y are given and the response is True/False. export lt_city($X, $Y).