Expression Pattern Language (eXPL)

eXPL Evaluation

Evaluation in eXPL also entails unification as variables are used in expressions and unification populates variables prior to evaluation. The following script provides a simple example of this, where the top 10 Asian cities are found from a set of facts about the highest populated cities of the world:

// axiom mega_city (Rank,Megacity,Country,Continent,Population)
// {1,"Tokyo","Japan","Asia",37900000}
// {2,"Delhi","India","Asia",26580000}...
include "mega_city.xpl";
integer count = 0;
template asia_top_ten (
  Megacity ? Continent == "Asia" && count++ < 10,
  Country, Population);
query asia_top_ten (mega_city : asia_top_ten);

Notice the short curcuit statement in the second term of the "asia_top_ten" template:

Megacity ? Continent == "Asia" && count++ < 10

Here the "Continent" variable is used in an expression and populated by the unification with the "Continent" term in the "mega_city" axiom. Here is the solution:

Megacity = Tokyo, Country = Japan, Population = 37900000
Megacity = Delhi, Country = India, Population = 26580000
Megacity = Seoul, Country = South,Korea, Population = 26100000
Megacity = Shanghai, Country = China, Population = 25400000
Megacity = Mumbai, Country = India, Population = 23920000
Megacity = Beijing, Country = China, Population = 21650000
Megacity = Jakarta, Country = Indonesia, Population = 20500000
Megacity = Karachi, Country = Pakistan, Population = 20290000
Megacity = Osaka, Country = Japan, Population = 20260000
Megacity = Manila, Country = Philippines, Population = 20040000

In the Megacity example, we can also see an aggregation variable "count" which counts the number of Asian cities in the solution. The count variable is declared and set to zero before it is used in the template. A variable can be used in a similar manner to produce averages, counts and other aggregation values.

The tutorial5 MegaCities code example runs this query.

Numerical Analysis

The eXPL language allows a flexible approach to dealing with data sets, a domain of the familiar spreadsheet. The following example shows how a sizeable and incomplete table of values can be input into an eXPL script to perform an analysis and produce readable data.

The "Increased Agriculture" example runs a "more_agriculture" query which produces a list of countries having increased the area under agriculture by more than 1% over the twenty years between 1990 and 2010. If you look at the agriculture-land.xpl file, you will see data for 210 countries with percentage values for each year spanning a 50 year period. Some of the values are 'NaN' indicating data not available.

include "agriculture-land.xpl";
include "surface-land.xpl";
template agri_10y (
  country ? Y2010 - Y1990 > 1.0,
  double Y1990, double Y2010);
template surface_area_increase (
  country? country == agri_10y.country,
  double surface_area =
    (agri_10y.Y2010 - agri_10y.Y1990)/100
    * surface_area_Km2);
// Specify term list to access the query output
list nation_list(surface_area_increase);
query more_agriculture(Data : agri_10y, surface_area : surface_area_increase);

The tutorial5 IncreasedAgriculture code example runs this query. The first 3 results are:

country = Albania, surface_area = 986.1249999999999
country = Algeria, surface_area = 25722.79200000004
country = American Samoa, surface_area = 10.0

To find more evaluation examples, have a look at Calculator.