DeALSFileRunner Primer

The FileRunner is intended for rapid program development. Given a file path, the FileRunner loads, compiles and executes any queries specified in the file, prints the query results to the console, and exits. Thus, the file must contain all database relation declarations, rules, facts and queries the user wishes to execute. The database declaration must be specified at the top of the file. Exports are optional, however it is good practice to use them to provide the compiler hints as to how to compile the queries you will be issuing.

The file format used by FileRunner is slightly different than that used with the GUI Editor as the 'query' construct is specially parsed by FileRunner. Queries must be specified in the file in order to be executed.

DeALS requires Java 1.8.

FileRunner By Example

For example, to find cities in Texas with populations greater than 400,000, we save the following in a file named ex_fr.deal in our working directory.

database({ city(Name:string, State:string) }).

lt_city(C, Pop) <-  city(C, 'Texas', Pop), Pop > 400000.

city('Houston', 'Texas', 3000000).
city('Dallas', 'Texas', 2000000).
city('Huntsville', 'Texas', 150000).
city('Austin', 'Texas', 750000).
city('Corsicana', 'Texas', 60000).
city('Shreveport', 'Louisiana', 90000).
city('Bastrop', 'Texas', 6000).
city('San Antonio', 'Texas', 1500000).

export lt_city(C,P).
export lt_city($C,P).

query lt_city(A,B).
query lt_city('Austin',B).

Note, export lt_city(C,P). tells the compiler that C and P are output variables, i.e. unbound when the query is issued. export lt_city($C,P). tells the compiler that $C will be bound (input). See the Query Forms section in The Basics for more details on exports and query forms.

Then we execute the programs with the runfile script with the file name as the only argument (e.g. "./runfile ex_fr.deal").

Oops! We have an error. Our database relation declaration and facts do not match. In fact, the relation declaration is missing the column for population. So we edit and save ex_fr.deal again.

database({ city(Name:string, State:string, Population:integer) }).

lt_city(C, Pop) <-  city(C, 'Texas', Pop), Pop > 400000.

city('Houston', 'Texas', 3000000).
city('Dallas', 'Texas', 2000000).
city('Huntsville', 'Texas', 150000).
city('Austin', 'Texas', 750000).
city('Corsicana', 'Texas', 60000).
city('Shreveport', 'Louisiana', 90000).
city('Bastrop', 'Texas', 6000).
city('San Antonio', 'Texas', 1500000).

export lt_city(C,P).
export lt_city($C,P).

query lt_city(A,B).
query lt_city('Austin',B).

Then we issue the "./runfile ex_fr.deal" command again.

Success! We observe that queries are executed in the order declared in the input file. Since two queries were declared, there are two query executions and their corresponding results. Note - The program and facts below are example1.deal and example1.fac from The Basics.

Troubleshooting

Common observed results and possible causes when using FileRunner are:

Observed Result Possible Cause
FileRunner writes nothing to console. No Queries declared.
Query returns no results. No Facts declared.
Editing file, but no change in error message. FileRunner-ing wrong file?


Last Updated 10/8/2014