
In Visual Prolog, it is normal to use the functional syntax for relations and choice points are created in the normal way - for example, the goal X = (std::fromTo(1,10))*10 succeeds with bindings X=10, X=20, X=30, X=40, etc. In the first example, we prevent this using cuts. Note that the <- operator and the functional-style predicate above still behave as relations - it is legal for them to have choice points and perform multiple unification. Finally, I expect to add some chapters on advanced topics you asked me for. It is also more 'interactive' as I include Test Zone where you can try and test your Prolog programs interactively within your Java-capable web browser. Multimangle(X,Y) :- Y = mangle(mangle(mangle(X))). This is a second edition of former Interactive Prolog Guide that brings new design and better organization of chapters.

For example, in Visual Prolog: mangle(X) = Y :- Y = ((X*5)+2). However, some modern Prologs go further and offer a custom syntax for this type of predicate. We can now write: multimangle(X,Y) :- X <- mangle(mangle(mangle(Y))). % If it's not a compound, just use is directly , % Rebuild a compound with the evaluated arguments R2 <- X2, % Recurse to evaluate the argumentsĮxpr =. % To make the new operator compatible with is.Ĭompound(X), % If the input is a compound/function % Define our function in terms of the infix operator - note the cut to avoid

In most Prologs, it is possible to avoid this by writing an alternate infix operator to use in place of is which expands expressions including the alternative function. multimangle(X,Y) :- mangle(X,A), mangle(A,B), mangle(B,Y). This can create the difficulty that if a function-style predicate is called multiple times, it is necessary to "daisy chain" temporary variables. Traditionally in Prolog, "functions" (with one output and bound inputs) were written as regular predicates: mangle(X,Y) :- Y is (X*5)+2.
