Basic Prolog operators and built-ins
                                                Succeeding Example

==      literal equality                        [foo, 5] == [foo, 5].

\==     literal inequality                      [foo, 5] \== [bar, 5].

=       unifiability                            [foo, X] = [Y, bar].

>       numeric greater (evaluates)             3+4 > 4-1.

<       numeric less (evaluates)                3+4 < 9-1.

>=      numeric greater-or-equal (evaluates)    3+4 >= 5+2.

=<      numeric less-or-equal (evaluates)       3+4 =< 5+2.

=:=     numeric equality (evaluates)            2+1 =:= 1+2.

=\=     numeric inequality (evaluates)          2+1 =\= 2+2.

@<, @>, @=<, @>= etc.  term comparison          foo @> bar.


Inter-goal operators:

\+      not provable                            \+ (foo = bar).

,       and                                     p(X), q(X, Y).

;       or                                      p(X, Y) ; q(X, Y).

-> ;    conditional                             p(X) -> q(Y) ; r(Y).

!       cut: failing back to this point
        fails the containing goal               p(X), !, q(Y).


Operators used on the right-hand side of 'is' for evaluation:

+       addition                                X is 3 + 4.

-       subtraction                             X is 3 - 4.

*       multiplication                          X is 3 * 4.

/       floating division                       X is 3 / 4.

//      integer division                        X is 3 // 4.

mod     integer remainder                       X is 12 mod 5.

float   floating equivalent of integer          X if float(4).

integer integer truncation of floating          X is integer(5/3).


Built-in predicates

setof(T, E, R)  R is the set of T such that E
                Note: This will fail if the set is empty.
                Sets are ordered and contain no duplicates; bags are not.

bagof(T, E, R)  R is the bag of T such that E
                Note: This will fail if the set is empty.

atomic          arg is atomic                   atomic(foo).

number(N)       arg is a number                 number(3.14).

integer(N)      arg is an integer               integer(3).

length(L, N)    length of a list                length([2, 4, 6], N).

append(L, M, R) R is M appended to L            append([1, 2], [4, 5, 6], R).

-------------------------------------------------------------------------------

How do I trace in prolog?

    trace.

To turn off the trace:

    notrace.

In basic trace mode, Prolog will stop before and after every goal and sub-goal.
Hit return to advance to the next step.  Type

    s

to skip over the execution this predicate internally.  When you get to the
exit of a predicate, you can type

    r

to redo it (so as to get a chance at single-stepping, in case you skipped
previously).

It is a good idea to trace inside an editor, such as an emacs shell.  In that
way, you can search back and forth through your output.

To see all trace output without stopping at each goal, use:

    leash(off).

To stop only at specific predicates, use

    spy(name/arity).

e.g. spy foo/3. for a 3-place predicate foo.  Type

    l

to "leap" to the next spied-upon predicate.  To not spy on a predicate
being spied upon, use

    nospy(name/arity).

There is quite a lot more available, but these are the basics.