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 two lists given as the first two arguments and returns the concatenated list through the third argument. Notice 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 given as the third argument. In fact, the call append(Xs,Ys,[a,b]) fails since it matches neither head of the clauses.
\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 to generate more compact and faster 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 in matching clauses can be significantly faster than its counterpart in standard clauses if multi-level indexing is effective.

When consulted into the program code area, matching clauses 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 2012-01-03