[m-users.] DCGs: equivalent of Prolog's phrase/2 and phrase/3 predicates?
Sean Charles (emacstheviking)
objitsu at gmail.com
Sun May 9 01:58:39 AEST 2021
Before setting off to the tattoo parlour I made one small change to keep it more ‘DCG’, I removed {true} and put in [] instead./..
skip_ws -->
( if ([' '];['\t'])
then skip_ws
else []
).
Nice work though!
> On 8 May 2021, at 16:54, Volker Wysk <post at volker-wysk.de> wrote:
>
> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210508/23e035b0/attachment.html>
More information about the users
mailing list