Skip to end of metadata
Go to start of metadata

match/3 (i,io,io)

This predicate is quite unique and is typically used internally in the Prova extension for functional programming (consulted from functional.prova).

What it does can be better illustrated with an example.

This example prints:

The idea behind match is that we should be able to iterate over facts (or rule heads) that match the pattern supplied in the first argument. The iteration is executed by repeated invocation as opposed to non-deterministic choice. The second output-only argument represents the actual fact as it is stored in the rulebase rather than the result of its unification with the pattern in the first argument. The third argument must be a free variable on first invocation but becomes instantiated to a special handle that could be compared to an iterator, allowing for subsequent invocations of match to return other matching facts. The match invocation finally fails when all the matching facts are exhausted.

Moreover, the handle G in the above example can be used in the update built-in predicate to update the matching fact directly in place, without retracting it and asserting back a modified version.

The functional extension hides match and update completely, allowing the user to simply define a mutator function that takes the complex term corresponding to a fact literal and produces a mutated version. This function is then passed to the functional pipeline that iterates over the facts and updates them accordingly.

Here is an example.

The fact table o undergoes a change that increments its second argument for all facts matching the pattern o(X,2). The second goal proves that all the o facts now have 3 in the second position and the original order of the o facts is preserved.

Labels: