marcel@uiucdcs.UUCP (10/26/83)
#N:uiucdcs:29700004:000:2011 uiucdcs!marcel Oct 25 20:22:00 1983 More on the purity vs convenience issue. And also on the failure vs error issue, which turns out to be related. Consider the following code: ?- op(200,fx,'*'). *(X) :- call(X), !. *(X) :- nl, write('! Could not execute: '), write(X), nl, !, fail. We can now write *goal(X,Y) as something I call an `action'. A large number of the "evaluable predicates" built into Prolog systems have just the nature of an action: that is, they have exactly one instantiation. But in Prolog they are not discriminated from goals with multiple instantiations by any textual means. Now as most reasonably experienced Prolog programmers will know, one frequently wants to write predicates that behave in exactly this fashion. The easiest (low-level) way to ensure a unique instance is to place a `cut' at the end of all the clauses for the predicate. Obviously, this does nothing to see to it that the predicate will succeed at all, leaving one with the failure vs error problem. And once again, someone reading the program can not tell, from looking at the predicate `call', that an action was wanted. I claim that a `*' in front of a predicate call is much preferred to several cuts within the predicate, even though (by itself) it doesn't replace the cut altogether (so we now have two control flow modifiers instead of one). `*' even has a reasonably logical definition, as well as being a debugging asset, as well as making it patently obvious where back-tracking can and cannot occur. I have been thinking along these lines for a while now, and have devised a small set (3 or 4) of (dare I say it) "higher-level" operators that can, between them, make back-tracking control (not logic program interpretation methods as studied by Pereira, Porto and Gallaire) much more transparent, to the extent of eliminating the cut. So, which is better: one uniform GOTO, or a whole handful like REPEAT-UNTIL, WHILE-DO, FOR-DO, IF-THEN-ELSE and CASE? Marcel Schoppers U of Illinois @ Urbana-Champaign