Re: Extended DCG?
"Abdallah, Samer" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
My example was boring. I thought I'd share this:
untextspeak(In, Out) :- trans( (In,Out), ([],[])).
trans --> [].
trans --> next, trans.
next --> \<"bang", !, \>"!".
next --> \<"c", !, \>"see ".
next --> \<"u", !, \>"you ".
next --> \<"r", !, \>"are ".
next --> \<"l8r", !, \>"later".
next --> \< (eyes,break(mouth),mouth), !. % ignore smileys. they are stupid.
next --> \< [X], \>[X]. % anything else gets through.
eyes --> ";"; ":".
break(P) --> []; \+P, [_], break(P).
mouth --> ")"; "("; "P".
test :- untextspeak("cu:-)l8rbang:--P",L),
format(L).
If anyone has a better DCG for smileys, please feel free to contribute.
Now I will do something useful.
Samer.
On 12 Feb 2014, at 20:38, Alan Baljeu <[email protected]>
wrote:
> I never bother with phrase/3, and just invoke my predicate xy(Rag, List, []). So maybe I could do xy(Rag, (List1, List2), ([],[])) and design xy to work? It's not clear to me how to pull this all together.
>
> Alan Baljeu
> From: "Abdallah, Samer" <[email protected]>
> To: Alan Baljeu <[email protected]>
> Cc: Prolog <[email protected]>
> Sent: Wednesday, February 12, 2014 1:48:07 PM
> Subject: Re: [SWIPL] Extended DCG?
>
> Hi all,
> I would just like to use this opportunity to request again that phrase/3 be
> allowed to work with arbitrary types in the last two positions, not just
> lists, or an alternative, say gphrase/3 (for generalised phrase), or
> rundcg/3 which works exactly like phrase/3 but allows arbitrary types.
> Or even better, put phrase/3 back how it was and introduce a type
> checking list_phrase/3 or safe_phrase/3 for people who want that.
>
> It used to be the case that an extended DCG for writing a transducer
> as Alan would like, was easy to write using ordinary DCG notation.
> The type of the threaded argument would be a pair of lists (L,R)
> instead of just one list. In my DCG library I have some DCG rules for
> working with this conveniently. For example, operators (\<)//1 and (\>)//1
> apply a DCG phrase to the left or right member of the pair:
>
> :- op(800, \<, fy).
> :- op(800, \>, fy).
>
> \<(P, (L1,R), (L2,R)) :- phrase(P,L1,L2).
> \>(P, (L,R1), (L,R2)) :- phrase(P,R1,R2)
>
> Then you can do things like \< integer(X) to read an integer from
> from the left sequence and \> [int(X)] to write a term to the right, and so on.
> Alan's scenario is easily and efficiently dealt with.
>
> Forcing us to use lists for the arguments to phrase/3 forces an ugly
> encoding of the pair in a singleton list, e.g. as [(L,R)], and, if the list
> is [X] and we already have a bunch of predicates that want to work
> on X, forces an unnecessary layer of meta-predicates to get through
> the wrapping.
>
> For the moment, I have deleted the two offending lines from boot/dcg.pl
> in my local installations, but of course, this is not good for the portability
> of my code!
>
> cheers,
> Samer
>
>
> (
>
> On 11 Feb 2014, at 16:51, Alan Baljeu <[email protected]>
> wrote:
> > I have a scenario where I'm mapping a list to a second list, but it's not 1 to 1. For this, it would be nice to use an extended DCG, that supports two independent lists. Does such a thing exist?
> >
> > Alan Baljeu
> > -------------- next part --------------
> > HTML attachment scrubbed and removed
> > _______________________________________________
> > SWI-Prolog mailing list
> > [email protected]
> > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
> >
>
>
-------------- next part --------------
HTML attachment scrubbed and removed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.iai.uni-bonn.de/pipermail/swi-prolog/attachments/20140212/9115684c/attachment.bin>