Next: Functions with Domain/Exclusion Up: Finite-Domain/Exclusion Functional Programming Previous: Finite-Domain/Exclusion Functional Programming

## Domains/Exclusions as Function Arguments

The use of finite domains as arguments of functions works like their use in relations. For instance, the two directed equations (``:-&'' is a left-to-right directed ``='')

```
dom[denmark,france,germany,italy,spain,sweden,uk]) :-& atlantic.```
use `anonymous' dom arguments for compactly defining a separates function. (They could be multiplied out to 24 domless equations, analogous to the 24 facts in section 7.)

The query

```
Destination)```
binds Source to dom[canada,usa], Destination to japan, and returns pacific; on backtracking it rebinds Destination to the European subdomain and returns atlantic.

Analogously, finite exclusions act as function arguments as was shown for relation arguments. For instance, the safe-divide function

```
safe-divide(Nominator,bnd[Denominator,exc[0]]) :-&
/(Nominator,Denominator).```
or, using a post-typing function definition (``:-'' and ``&'' permit intervening relational premises),
```
safe-divide(Nominator,Denominator) :- Denominator is exc[0] &
/(Nominator,Denominator).```
`excludes' Denominator-named arguments which would lead to division by zero.

Thus, the query

```
safe-divide(8,4)```
returns 2 because 4 0 is true. On the other hand, the query
```
safe-divide(8,0)```
yields unknown (rather than an error from the ``/''-built-in) because 0 0 is false.

Many function definitions, e.g. factorial and fibonacci (below) over the naturals, become more declarative than in PROLOG by excluding, in a defining clause, arguments of earlier clauses: the definition thus needs no cut and in fact has disjoint, order-independent (`OR-parallel') clauses. The fib definition can even be shortened to two clauses via complementary dom and exc arguments:

```
fib(dom[0,1]) :-& 1.
fib(bnd[N,exc[0,1]]) :-& +(fib(-(N,2)),fib(-(N,1))).```

Next: Functions with Domain/Exclusion Up: Finite-Domain/Exclusion Functional Programming Previous: Finite-Domain/Exclusion Functional Programming

Harold Boley & Michael Sintek (sintek@dfki.uni-kl.de)