Re: List decomposition.



Dear Pierpaolo,

BTW, your predicate, I'd write it in this way:

decompose(Item,[_|List]) :-
append(List2,[_],List),
member(Item,List2).

Or even:

decompose(Item,[_|List]) :-
decompose_1(Item,List).

decompose_1(Item,[Item,_|_]).
decompose_1(Item,[_|Rest]) :-
decompose_1(Item,Rest).


Or perhaps, for readability,

in_the_middle(Item,[_,Second,Third|Tail] :-
before_the_last(Item,[Second,Third|Tail]).

before_the_last(Item,[Item,_|_]).
before_the_last(Item,[_,Second,Third|Tail]) :-
before_the_last(Item,[Second,Third|Tail]).

Best regards,

Bill

.