[m-users.] DCG and optional whitespace term

Volker Wysk post at volker-wysk.de
Sun May 9 01:09:24 AEST 2021


Am Samstag, den 08.05.2021, 15:37 +0100 schrieb Sean Charles
(emacstheviking):
> 
> :- pred skip_ws(list(char)::in, list(char)::out) is semidet.
> skip_ws --> [C],{char.is_whitespace(C)}, skip_ws.
> skip_ws --> [].

> (...)

> The compiler outputs the following error message:
> 
> repl.m:118: In `skip_ws'(in, out):
> repl.m:118:   error: determinism declaration not satisfied.
> repl.m:118:   Declared `semidet', inferred `multi'.
> repl.m:120:   Disjunction has multiple clauses with solutions.

The second clause for skip_ws will always succeed. Therefore skip_ws can
have several solutions (first and second clause). When the first clause
succeeds, it doesn't mean that the second one is skipped, like you've done
it with a cut in your Prolog version.

skip_ws will have solutions for all prefixes of white space at the beginning
of the text. The "multi" determinism category is correct.

Bye
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20210508/4be7f035/attachment.sig>


More information about the users mailing list