DeAL TutorialThe Basics
Example: Cities Database Schema
|
|
Facts and Schema
FactsFacts correspond to tuples in the database. For example,
city('Houston', 'Texas', 3000000). distance('Austin', 'Waco', 110). assembly(wheel, spoke, 36).
- Variables start with capital letters.
- Constants that begin with a capital letter are enclosed in single quotes.
- city('Houston', 'Texas', 30000) corresponds to the row ('Houston', 'Texas', 30000) in the city table.
database( { city(Name:string, State:string, Population:integer), distance(City1:string, City2:string, Distance:integer) } ).
- Each predicate (relation) is named.
- Each column is (optionally) named.
- Each column is assigned a data type.
- Datatypes are: integer, long, float, string, complex, list, any.
- Columns of type any can contain complex terms (functors).
Rules and Queries
Derived 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.
Example: List all cities in Texas with where the population exceeds 400,000.
query lt_city(C, Pop).
This query will return:
lt_city(`Houston`, 3000000) lt_city(`Dallas`, 2000000) lt_city(`Austin`, 750000) lt_city(`San Antonio`, 1500000)
Query Forms
- A query form, or export, is a generic query that specifies for the DeAL compiler which of the arguments will be given and which are expected as output when a query of that type is issued.
- The given bindings in an export allow the compiler to optimize the access to the data.
- Exports can be specified for base predicates as well as derived predicates that are defined via the programs' rules.
For instance, if the program file contains:
export lt_city($X, Y).
Then, the user can compile this export, and then run the following query:
query lt_city('Austin', Pop).
The answers are then returned (but if no export matches this bound/free pattern, an error message is returned).
Example: Query Forms
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).
Constructs
Basic Language Constructs- Numbers
Integer or Real (float).
- Constants
A constant is a string of symbols beginning with a lowercase letter. Constants are names of objects such as chain_stay, joe . If we want to use constants starting with an uppercase letter, then we must enclose them in quotes, e.g., 'Houston'.
- Variables
A variable is a string of symbols beginning with an uppercase letter. Examples are Subpart, Price, X123. Variables denote unspecified values that are assigned during the execution of a DeAL program.
- Numbers, constants, and variables are included in the syntactic subclass called terms.