[m-users.] DCGs: equivalent of Prolog's phrase/2 and phrase/3 predicates?

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


Am Samstag, den 08.05.2021, 16:26 +0100 schrieb Sean Charles
(emacstheviking):
> 
> In the end I made it `set` like this, I don’t see why skipping whitespace should fail anyway, if it isn’t there then the next part of the calling rule can deal with it!
> 
> :- pred skip_ws(list(char)::in, list(char)::out) is det.
> 
> skip_ws(In, Out) :-
>     trace[io(!S), run_time(env("FELT_DBG"))]
>     (io.format("skip_ws: ",[],!S),
>      io.print_line(In,!S)
>     ),
>     ( if [C|Cs] = In then
>         ( list.member(C, [' ', '\t']) ->
>             skip_ws(Cs, Out)
>         ;
>             Out =In
>         )
>         else
>             Out = In
>     ).

This could be written like this:

:- pred skip_ws(list(char)::in, list(char)::out) is det.
skip_ws -->
    ( if ([' '] ; ['\t'])
      then skip_ws
      else { true }
    ).


Cheers,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/cb39051d/attachment.sig>


More information about the users mailing list