Re: Flatten, question

Lindsey Spratt <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Use append(FlatHead, FlatTail, List) instead of concat(...).

concat/3 is for combining atoms to create a new atom. append/3 is for  
appending lists to create a new list: more generally it is true if the  
third argument is the list that is the second argument list appended  
to the first argument list.

Lindsey

On Oct 30, 2008, at 2:13 PM, Hartmut Lange wrote:

> Everybody,
> is somebody here who can help me in this small algorithm.
> Why do I get
>  atom_concat/3: Type error: `atomic' expected, found `[g]'
>  atom_concat/3: Type error: `atomic' expected, found `[e]'
> in the line where flatten1(...) is called with the list of a,b,c...
> What's wrong with that... hmm? I found it in the Prolog book of  
> Bratko, excercise 3.11
> I am using SWI-Prolog 5.6
> Regards,
>
>
> flatten1([Head|Tail], List) :-
>    flatten1(Head, FlatHead),
>    flatten1(Tail, FlatTail),
>    concat(FlatHead,FlatTail, List).
>
> flatten1([], []).
> flatten1(X, [X]).
>
> :- flatten1([a,b,c,e,f,g], List),
>   write('Flat List:'), write(List).
>
> :- flatten1([a,b,[c,e],f,g], List),
>   write('Flat List:'), write(List).
>
>
> _______________________________________________
> Users-prolog mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/users-prolog
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.