Re: Suggestions for dcg_basics

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 10/17/2013 02:56 AM, Richard A. O'Keefe wrote:
>
> On 16/10/2013, at 8:53 PM, Boris Vassilev wrote:
>
>> There is one small detail about string//1 that bothers me, probably because
>> I don't understand how to use it properly:
>>
>> in its current implementation, it takes as few tokens as possible, and
>> takes more on backtracking.  So, for a n-token string, it will fail and
>> backtrack n-1 times.
>
> The definition is just
>
>      string([]) -->
>          [].
>      string([X|Xs]) -->
>          [X],
>          string(Xs).
>
> (By the way, string//1 is a *bad* name for this predicate because it is
> *NOT* in any way restricted to strings.  It will match a list of XML
> elements as happily as anything else.  And yes, it does make a lot of
> sense to use DCG with sequences of XML terms.)

Not sure I agree here.  The library as a whole is defined to do 
meaningful things with strings of character codes, such as parsing
numbers, skipping blanks, etc.  In that context string//1 is IMHO
a fair name.  This doesn't exclude an equivalent predicate with
a different name that fits another domain.

> I really don't see what it _could_ do other than what it does.

You could swap the clauses to make it greedy ... Most likely a
bad idea :-)

	Cheers --- Jan
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.