Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Prolog: Call by pattern


1. Prolog: Call by pattern

2. Parameter passing
Many imperative programming languages support the following for communication of actual parameters to formal parameters.

3. Call by pattern
In Prolog, call by reference is achieved by passing an unassigned logical variable (that can only be assigned once, backtracking undoes the assignment).

For lack of a more descriptive term, Prolog has what can be described as a call by pattern (matching).

Below are some examples to illustrate the concept. Here is the Prolog code.

Here are the calls.
   run(2 + 3 * 5),    run('+'(2, '*'(3, 5))),

Here is the output of the Prolog code.


4. Term structures
What appears to be an arithmetic expression
2 + 3 * 5

is actually the following term structure.
'+'(2, '*'(3, 5))

The single quotes are used to represent a symbol (or symbols) as an atom.

5. Term structures
What appears to be an arithmetic expression
(2 + 3) * 5

is actually the following term structure.
'*'(+'(2, 3),5)

The single quotes are used to represent a symbol (or symbols) as an atom.

6. End of page