[eclipse-clp-users] Dealing with ambiguity between empty arrays and empty lists

From: Alex Mahrer <alex.mahrer_at_adventiumlabs.com>
Date: Wed, 04 Dec 2013 13:50:02 -0600
Lists are defined in ECLiPSe as recursive data structures with root term
'[]' so that an empty list is represented by the atom '[]'. Arrays are
simply compound terms with functor '[]', thus empty arrays are also
represented by the atom '[]'.

This ambiguity leads to inconsistencies in instances where empty arrays
must be distinguished from empty lists. As an example, consider the
following query that uses dim/2 to both create a two-dimensional array
and retrieve the dimensions of that array:

?- dim(Array2D, [3, 0]), dim(Array2D, Dims).

Array2D = []([], [], [])
Dims = [3]

In this example, the dimensions provided to dim/2 in the first call do
not match the dimensions that it derives from the array in the second call.

Two approaches to dealing with this problem come to mind:
1) Avoid the use of empty arrays.
2) Represent arrays using a different functor, and rewrite all
predicates that handle arrays to accommodate.

Neither of these approaches is ideal. Are there any alternatives that
I'm missing?

Thanks,
Alex
Received on Wed Dec 04 2013 - 20:10:20 CET

This archive was generated by hypermail 2.2.0 : Tue Dec 10 2013 - 06:13:25 CET