3 ms·
Languages you must know #7 (OPS5)
OPS5 by Charles Forgy is a rule-based programming language.
Rule-based languages formed the basis of "expert systems". The idea is to interview an expert in some subject (e.g. car repair) and then write "rules" that will "match" the situation and perform the action. For example,
(rule bad-breaks
when (step on break pedal)
and (pedal offers no resistance)
and (car does not slow down)
then
(fix the breaks))
Given a set of "rule patterns" it is possible to compute a set of actions. Rules can be easily written to "capture knowledge". If a new situation occurs then a new rule can be added.
The system matches every situation against every rule and chooses "the best one" (the match-action cycle).
A whole industry of "Expert Systems" grew around this idea.
Of course, there is a question of efficiency. Given 10,000 rules you really don't want to match every rule every time. Forgy figured out a highly efficient mechanism, called the RETE network, to solve this problem.
Rule based programming is a different way to approach a problem. It provides a solution "near to the problem", is semi-declarative so it can be easily read, and can be easily extended.
It can also easily be "randomly buggy" as rules that "fire" perform an action that changes the situation... which causes another rule to operate... etc.
The "reasoning" can be hard to follow.
But, as we are interested in "why" and "what", rule-based programming will change your mindset about programming.
OPS5 is a "must know" language.