Failure-handling as fundamental
Mon Feb 4 07:46:01 2002
> A "true" program is one which terminates without failure.
> A "false" program is one which fails.
This is exactly how Prolog works. And it works very nice, especially
when combined with unification of variables (two-way pattern-matching)
and backtracking. For example, Prolog expression
X = pair("a", Y)
where uppercase X and Y are variables and lowercase pair is a
- succeed if X is instantiated as a pair, it's first component is the
string "a" and the second can be unified with Y.
- fail if X is not instantiated as a pair that matches the pattern
- if X is not instantiated, the expression will succeed and X will be
unified with the pattern, i.e. it will match the pair construct for all
the expressions that follow. If any of the following expressions fails,
the unification of X will be "undone" before any or-alternative is tried.
Anyway, this is what more-or-less happens on the low level. Reading
Prolog is easier if you regard the "expressions" I mention as logical
statements and the "sequences" of succeeding expressions as logical
conjunctions of these statements. After you wrap your mind around it, it
actually becomes quite easy. But I think it's easier to do if you first
understand what really happens on the low-level, and for some reason no
Prolog course seems to be arranged that way. After the demise of AI, the
language went the way of Forth and APL.