Example:


\begin{picture}(380,1)(0,0)
\put (0,0){\framebox{(}380,1)}
\end{picture}
      append([],Ys,Zs) => Zs=Xs. 
      append([X|Xs],Ys,Zs) => Zs=[X|Zs1],append(Xs,Ys,Zs1).
This predicate concatenates the two lists that are given as the first two arguments, and returns the concatenated list through the third argument. Note that all output unifications that bind variables in heads must be moved to the right-hand sides of clauses. In comparison with the counterpart in standard Prolog clauses, this predicate cannot be used to split a list that is given as the third argument. In fact, the call append(Xs,Ys,[a,b]) fails, since it matches neither of the clauses' heads.
\begin{picture}(380,1)(0,0)
\put (0,0){\framebox{(}380,1)}
\end{picture}

Matching clauses are determinate, and employ one-directional matching rather than unification in the execution. The compiler takes advantage of these facts in order to generate faster and more compact code for matching clauses. While the compiler generates indexing code for Prolog clauses on at most one argument, it generates indexing code on as many arguments as possible for matching clauses. A program that is written by using matching clauses can be significantly faster than its counterpart that is written by using standard clauses, if multi-level indexing is effective.

When matching clauses are consulted into the program code area, they are transformed into Prolog clauses that preserve the semantics of the original clauses. For example, after being consulted, the membchk predicate becomes:

      membchk(X,Ys):- $internal_match([Y|_],Ys),X==Y,!. 
      membchk(X,Ys):-$internal_match([_|Ys1],Ys),membchk(X,Ys1).
where the predicate $internal_match(P,O) matches the object O against the pattern P.

Neng-Fa Zhou 2013-01-25