Subject: RE: split/3

From: Alfonso Ortega de la Puente <[email-masked]>
Date: Wed, 3 Nov 1999 17:41:53 +0100

The predicate from Luis Iraola seems to be useful...but it changes the type of the arguments that Joakim 
handles.

It could be useful to define the following transformation predicate:

list_chars_list_atoms([], []).
list_chars_list_atoms([A|B], [C|D]) :-
        atom_char(C, A),
        list_chars_list_atoms(B, D).

And use it like this:

atom_chars(axaxxa,L),list_chars_list_atoms(L,LA).

L = [97, 120, 97, 120, 120, 97]
LA = [a, x, a, x, x, a] 

In order to use then the predicate from Luis Iraola

segment(LA, [a], List).

-----Mensaje original-----
De:	Luis Iraola Moreno [SMTP:[email-masked]]
Enviado el:	miércoles 3 de noviembre de 1999 13:39
Para:	Joakim Örblom
CC:	[email-masked]
Asunto:	Re: split/3

On Wed, 3 Nov 1999, Joakim Örblom wrote:

> Help! How do I construct a predicate split/3?? E.g. 
> split(a,axxaxxaxx,[xx,xx,xx]).
> Thanx from Carl Orblom ([email-masked])

This predicate may do the job:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% segment(InputList, SegmentSeparator, SegmentList)
%

segment([], _, []).

segment([X|Y], [H|T], [Segment|Tail]):-
	append(Segment,[H|U], [X|Y]),
	append(T, Rest, U),
	!,
	segment(Rest, [H|T], Tail).

segment([X|Y], _, [[X|Y]]).

Example:

?- segment([a,x,x,a,xx],[a],L).

L=[ [], [x,x], [xx] ] 

----------------
* To UNSUBSCRIBE, please use the HTML form at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to [email-masked] using the Subject: "unsubscribe"
(without the quotes) and *no* message body.

** An ARCHIVE of this list is maintained at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/