I am new in Prolog and trying to learn it. I came across a question and I am trying to run it but I think I am making a fundamental mistake and my code does not work properly. I am trying to write a predicate that takes two arguments. The first argument is a list and the second argument is a list which members are the members of the first list, repeated twice.
Here is my code :
twice([],[]).
twice([X|Taila],[X,X|Tailb]) : twice(Taila,Tailb).
For example
twice([z,4,hello],X).
should return
X = [z,z,4,4,hello,hello]).
:should be:-in your second clause. - Shontwice(Xs, Ys).And look what you get there. - falsetwice([z,4,hello],X).? And if this is your exact code, as @aBathologist noted, you have a typo. Was that the problem? - SQB