DeAL TutorialThe Basics

Cities Database (.deal | .fac)

Example: Cities Database Schema

CITY
NAME STATE POPULATION
Houston Texas 3,000,000
Dallas Texas 2,000,000
Huntsville Texas 150,000
Austin Texas 750,000
Corsicana Texas 60,000
Shreveport Louisiana 90,000
Bastrop Texas 6,000
San Antonio Texas 1,500,000
DISTANCE
CITY1 CITY2 MILES
Houston Bastrop 130
Houston Huntsville 60
Huntsville Dallas 100
Austin Waco 110
Waco Dallas 100
Dallas Shreveport 200
Austin Bastrop 30
Austin San Antonio 80
San Antonio Houston 190

Facts and Schema

Facts

Facts 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.
Schema
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. 
  • 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 that 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(`Houston`, 3000000)
    lt_city(`Dallas`, 2000000)
    lt_city(`Austin`, 750000)
    lt_city(`San Antonio`, 1500000)
    
  • Queries without variables (a.k.a. closed queries) return a true/false answer.

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.

Last Updated 2014