sub_string/5 (was Re: Ann: SWI-Prolog 6.5.3)

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 11/22/2013 01:57 AM, Richard A. O'Keefe wrote:
> 
> On 22/11/2013, at 2:33 AM, Boris Vassilev wrote:
> 
>> P.S. And there is actually no immediately obvious "sub_list" built-in list
>> predicate for efficient searching for (overlapping) substrings in a
>> list.... Or again, I have not paid enough attention when reading.
> 
> It's not quite clear to me what you want here.
> 
> The Quintus library included
> 
> substring(Whole, Part, Before, Length, After)
>     is true when Whole = Front ++ Part ++ Back
>     and length(Front, Before)
>     and length(Part, Length)
>     and length(Back, After).
> 
> substring(Whole, Part, Before, Length) :-
>     substring(Whole, Part, Before, Length, _).
> 
> substring(Whole, Part, Before) :-
>     substring(Whole, Part, Before, _, _).
> 
> substring(Whole, Part) :-
>     substring(Whole, Part, _, _, _).
> 
> SWI Prolog has
> 
> sub_string(Whole, Start, Length, After, Part)
> 
>   -- The argument order is not friendly to dropping
>   -- unwanted length arguments.

It is modelled after ISO sub_atom/5.  I think that is the
most sensible thing to do.

>   -- The name Start suggests a 1-origin *position*,
>   -- in fact, like substring/5 it uses a 0-origin *offset*.

The ISO standard describes this argument as `Before'.  I now
copied that.  Made the docs a bit more elaborate and consistent.

	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.