Matching tuples in Prolog

Posted by milosz on Stack Overflow See other posts from Stack Overflow or by milosz
Published on 2010-05-23T22:32:59Z Indexed on 2010/05/23 22:41 UTC
Read the original article Hit count: 239

Filed under:
|
|

Why does Prolog match (X, Xs) with a tuple containing more elements? An example:

test2((X, Xs)) :- write(X), nl, test2(Xs).                                    
test2((X)) :- write(X), nl.                                                   

test :-                                                                       
        read(W),                                                               
        test2(W). 

?- test.
|: a, b(c), d(e(f)), g.
a
b(c)
d(e(f))
g
yes

Actually this is what I want to achieve but it seems suspicious. Is there any other way to treat a conjunction of terms as a list in Prolog?

© Stack Overflow or respective owner

Related posts about list

Related posts about prolog