[m-users.] An inst and an exception

Volker Wysk post at volker-wysk.de
Sat Jan 20 14:53:23 AEDT 2024


Am Samstag, dem 20.01.2024 um 02:47 +1100 schrieb Zoltan Somogyi:
> On 2024-01-20 02:37 +11:00 AEDT, "Volker Wysk" <post at volker-wysk.de> wrote:
> > transform(Extr, [Row|Rows], [Data|Rest]) :-     % <- line 1010
> >     (
> >         if   Data0 = Extr(Row)
> >         then
> >              Data = Data0,
> >              transform(Extr, Rows, Rest)
> >         else
> >              throw(match_error(Row))            % <- line 1017
> >     ).
> > 
> > 
> > I get this from the compiler:
> > 
> > odbc.m:1010: In clause for `transform(in((func(in) = out is semidet)),
> > odbc.m:1010:   in((odbc.one_element_list)), out((odbc.one_element_list)))':
> > odbc.m:1010:   mode error: argument 3 had the wrong instantiatedness.
> > odbc.m:1010:   Final instantiatedness of `HeadVar__3' was
> > odbc.m:1010:   `unique('[|]'(ground, ground))',
> > odbc.m:1010:   expected final instantiatedness was
> > odbc.m:1010:     named inst one_element_list
> > odbc.m:1010:     which expands to
> > odbc.m:1010:       bound(
> > odbc.m:1010:         '[|]'(
> > odbc.m:1010:           ground,
> > odbc.m:1010:           named inst exception.[]
> > odbc.m:1010:           which expands to
> > odbc.m:1010:             bound(
> > odbc.m:1010:               []
> > odbc.m:1010:             )
> > odbc.m:1010:         )
> > odbc.m:1010:       ).
> > 
> > Where does that "unique" come from?
> 
> The errror message says that the error is about the third argument
> in the clause head. You construct the term [Data | Rest] there,
> and since you don't store the reference to that term anywhere else,
> that reference is unique. That is NOT the problem.
> 
> > What does that "named inst exception.[]"
> > mean? Does that error message relate to line 1017?
> 
> 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 [].

The first clause would belong to a different mode, it doesn't match a one-
element-list as its input. Is that the reason for why it isn't considered?

Cheers,
Volker


More information about the users mailing list