0
votes

I'm trying to write hasRepetition that 'recives' a list and returns true if and only if it has repetitions in it.

I wrote : hasRepetition([Head|Tail]) :- member(Head,Tail);hasRepetition(Tail).

7 ?- hasRepetition([1,1]). ERROR: toplevel: Undefined procedure: hasRepetition/1 (DWIM could not correct goal)

2

2 Answers

3
votes

Your procedure definition is fine.

I guess you forgot to consult your code, i.e. consult(name). where name is the name of the file that has your code.

1
votes

I think @gusbro already give you the answer (+1). But please note that the procedure you wrote its' very inefficient.

First, memberchk/2 instead of member should be used. Then, put a cut before the disjunction. Otherwise, your code will be very slow, if called on backtracking (for instance, inside a findall...)