Re: Extended DCG?

Anne Ogborn <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
It's usually possible to do the mapping in one step, though not always
advisable. 

How about mapping the list to an intermediate list.?

example - language that maps strings like axayaz to bxbybz except we
always ignore f and the letter r gets replaced with zoom.
Could be done with one list, but more complex examples might find it easier 
to map it in two steps. So I'll do some in the first and some in the second
transform.

afayar  becomes bybzoom

phrase(first_lang(Intermediate), Source),
phrase(second_lang(Intermediate), Dest).

first_lang([]) --> [].
first_lang(X) --> "af", !, first_lang(X).   % remove the f's in first list
first_lang([X |Rest]) --> "a", [X]   % strip out the separator a's

second_lang([]) --> [].
second_lang([0'b, 0'z, 0'o, 0'o, 0'm |Rest]) --> "r", second_lang(Rest).
second_lang([0'b, X | Rest]) --> [X], second_lang(Rest).


=====

Same example, worked as a single list

phrase(first_lang(Dest), Source),

first_lang([]) --> [].
first_lang(X) --> "af", !, first_lang(X).   % remove the f's in list
first_lang([0'b, 0'z, 0'o, 0'o, 0'm |Rest]) --> "r", first_lang(Rest).

first_lang([0'b, X |Rest]) --> "a", [X]   % strip out the separator a's

I'm being slow about catching up to 7 rules, and being lazy and not checking the
code cause I need to dash off, so there may be some small errors in this.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.