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

Sean Charles (emacstheviking) objitsu at gmail.com
Sun May 9 01:56:09 AEST 2021


Wow, that’s beautiful.  I am off to the tattoo parlour with a printout.

I shall study that, it feels more like Prolog as well

Cheers man!

Sean


> 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



More information about the users mailing list