[m-users.] An inst and an exception

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Jan 20 18:08:55 AEDT 2024


On 2024-01-20 14:53 +11:00 AEDT, "Volker Wysk" <post at volker-wysk.de> wrote:
>> The error message says that it is not about this clause *in general*;
>> it is about this clause in the mode of the transform predicate that
>> promises that the third argument is a one element list. The error
>> says that the compiler can see that the list has at *least* one element,
>> but it cannot see why it can't have *more than one* element.
>> In other words, it expects Rest to be [], but the code computing its value
>> does NOT promise to return [].
> 
> I thought that when transform is called with a one-element-list, the
> compiler concludes that Rows is empty. Then it would call "transform(...,
> Rows, Rest)". This would match the first clause, that is to say
> "transform(_, [], []).", which says that Rest is empty. It second clause
> doesn't match. So we would have "[Data|Rest]" as a one-element-list, Rest
> being [].

When the compiler processes the recursive call, it looks ONLY at the
mode, or modes, of the called predicate. It does NOT look at the CODE
of the called predicate. If it did, that would be the start of a slippery slope:
should it look at the code of the predicates called by the callee? At the
code of the predicates *those* predicates call? And so on.

> The first clause would belong to a different mode, it doesn't match a one-
> element-list as its input.

What mode? The code in your email does not declare a mode in which
the second argument is an empty list. The compiler cannot consider
a nonexistent mode. When you call transform with the empty list as
the second argument, the compiler sees only one applicable mode,
which is the first, general mode, in which the second and third arguments
are in and out respectively. That is why it knows that Rest, the third arg,
will be ground, but knows nothing about its shape.

Zoltan.


More information about the users mailing list