# CS322 Fall 1999Module 8 (Metainterpreters)Assignment 8

## Solution.

In this assignment you will implement, in CILog, a new programming language ArLog that allows for adjustable parameters in arithmetic expressions and user-defined arithmetic functions.

An ArLog program is a set of clauses of the form:

```H <= B.
```
where H is an atom and B is a body.

A body is either of the form:

• `true`
• `A & B ` where A and B are bodies
• `A ` where A is an atom defined by rules
• `X is Exp ` where X is a number and Exp is a parametrized arithmetic expression. This is true if X is the value of the expression Exp.
• `assign(P,Exp) ` where P is a parameter and Exp is a parametrized arithmetic expression. This assigns the value of Exp to the parameter P.
• `E1 > E2 ` where E1 and E2 are parametrized arithmetic expressions. (This, "assign" and "is" are the only built-in relations).

Parametrized expressions are of the form:

• `A+B`, `A*B`, `A-B`, `A/B` where A and B are parametrized expressions
• `N ` where N is a number
• `P ` where P is a parameter (a CILog constant).
• a user-defined function

Parametrized expressions are always evaluated in an environment, where an environment is a list of terms of the form `val(P,V)` where P is a parameter and V is a number.

We always prove goals within an environment, but the environment can be updated with an assign goal. In a conjunction, the rightmost conjunct is evaluated in the environment that is the result of the evaluation of the leftmost conjunct.

As well as normal clauses defining atoms, the user can define functions using:

```F=Exp <= B.
```
Where F is a user-defined function and Exp is an expression. If B is true, the value of Exp is the value that F evaluates to.

You can also download a CILog implementation of ArLog, as well as a sample ArLog program.

• Question 1
• Question 2
• Question 3
• Question 4

• David Poole