Search code examples
prologsyntax-errorclpfd

Keep getting "Syntax error: Operator expected" when writing binary tree enumeration in prolog


I am new to Prolog, and I am writing a program to enumerate the binary trees in Prolog. Here is my program:

tree(0,[]).
tree(N,[L,R]):-
  N #> 0,
  N #= N1 + N2 + 1,
  N1 #>= 0, N2 #>= 0,
  tree(N1,L), tree(N2,R).

However, I keep getting

Syntax error: Operator expected

on line 3 at N. I tried to eliminated spaces or to retype the code manually again, but it doesn't work.


Solution

  • Add

    :- use_module(library(clpfd)). % SICStus, SWI
    

    or

    :- use_module(library(clpz)). % Scryer, SICStus