Reputation: 9472
I'm reading The Power Of Prolog, and have got as far as the section on the Collatz sequence.
I copied and pasted the code from there, adding the appropriate use_module
line before...
use_module(library(clpfd)).
hailstone(N, N).
hailstone(N0, N) :-
N0 #= 2*N1, % Error
N0 #> 1, % ensures termination
hailstone(N1, N).
hailstone(N0, N) :-
N0 #= 2*_ + 1, % Error
N0 #> 1, % ensures termination
N1 #= 3*N0 + 1,
hailstone(N1, N).
However, when I try to compile this, I get an error "hailstone.pl:nn:10: Syntax error: Operator expected" on the two lines commented above.
Anyone any idea what the error is, and why I get it? As you can see, I'm including the CLPFD module, so it should recognise #=
as an operator.
I tried using library(clpfd).
instead of the first line, but it didn't make any difference.
I'm using SWI-Prolog in case it makes any difference. Thanks.
Upvotes: 0
Views: 111