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

From: Joachim Schimpf <jschimpf_at_...311...>
Date: Wed, 11 Dec 2013 16:19:14 +0000
On 09/12/2013 23:16, Alex Mahrer wrote:
> Thank you both for the prompt responses.
> 
> On 12/4/2013 8:30 PM, Sergii Dymchenko wrote:
>> Hi,
>>
>> Is this a real practical issue?
> 
> The previous example using dim/2 demonstrated how the ambiguity of the
> two representations manifests itself as an issue. As a practical example
> of this issue, consider a predicate that calculates the total number of
> integers contained in an integer array of arbitrary dimensions.
> 
> int_count(MultiArray, N) :-
>   dim(MultiArray, Dims),
>   (foreach(D, Dims), fromto(1, In, Out, N) do
>     (Out is In * D)
>   )
> .
> 
> The following query then results in an incorrect value for N.
> 
> ?- int_count([]([], [], []), N).
> 
> N = 3
> 
>> Will the approach 2 solve the problem of not matching dimensions in the
>> following case?
>>
>> ?- dim(Array2D, [3, 0, 777]), dim(Array2D, Dims).
>>
>> Array2D = []([], [], [])
>> Dims = [3]
>>
>> Sergii.
> 
> The above query is semantically void. Compound terms with arity zero
> contain no sub terms by definition. In this case, dim/2 should return an
> error.
> 
> On the other hand, the query below does have meaning - one that is
> important in contexts where arbitrary arrays may be accepted as parameters.
> 
> ?- dim(Array2D, [3, 0]), dim(Array2D, Dims).
> 
> I think it is important to consider '[]' as an empty array in this case
> since empty arrays have been shown above to be useful in the degenerate
> cases of multidimensional arrays. In other words, the output should
> resemble:
> 
> Array2D = []([], [], [])
> Dims = [3,0]
> 
> Furthermore, as of version 6.1 #175, array-handling predicates including
> do/2 (with foreachelem as its iter spec), array_list/2, array_flat/2,
> and array_concat/3 treat the atom '[]' as an empty array. I think it
> makes sense for dim/2 to follow suit, since what makes arrays distinct
> from arbitrary compound terms is support from these built-in predicates.

Owing to the ambiguity of [] being either an atom, the empty list,
or an empty array, it is probably not possible to get the intended
interpretation automatically in all conceivable circumstances.

However, in reaction to Alex's observations (and his bug report
http://eclipseclp.org/bugzilla-4.0.2/show_bug.cgi?id=760) I have
made some modifications with the aim of improving consistency.

I have written a note about the issues at
http://eclipseclp.org/wiki/Joachim/Arrays
I'm happy to discuss further fine-tuning...

Cheers,
Joachim
Received on Wed Dec 11 2013 - 16:19:38 CET

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:30 CEST