Path: utzoo!attcan!uunet!munnari!murtoa.cs.mu.oz.au!munnari.oz!lee From: lee@munnari.oz (Lee Naish) Newsgroups: comp.lang.prolog Subject: Re: Committed Choice Message-ID: <1305@murtoa.cs.mu.oz.au> Date: 20 Mar 89 02:08:47 GMT References: <11500012@hpldola.HP.COM> <733@gould.doc.ic.ac.uk> Sender: news@cs.mu.oz.au Reply-To: lee@munmurra.UUCP (Lee Naish) Organization: University of Melbourne, Comp Sci Dept Lines: 53 In article <733@gould.doc.ic.ac.uk> cdsm@doc.ic.ac.uk (Chris Moss) writes: >There are 2 reasons for choice of control structures in Prolog: >efficiency and clarity. Certainly from a theoretical point of view >(the "power" of the system) if then-else is adequate, but there are >lots of reasons why it's given problems. See for instance the appendix >in Ehud Shapiro's book "Algorithmic Program debugging" which uses >conditionals far more than his later book "Art of Prolog". (He had an >argument with David Warren and lost!). As I understand it, the reason why the argument was lost was that *in DEC-10 Prolog* '->' is not compiled and is therefore much slower. I don't know of any other Prolog system where this is the case. In fact, -> is significantly more efficient than ! in some systems for some simple conditions. For example: ( A < B -> ... ; ...) does not create a choice point in Quintus or NU-Prolog. The equivalent code using cut does (this may not be the case forever). >Well for one thing there are different variations even of if-then-else! (and cut, as Chris has pointed out in the past) >For example, does an if-then without an else fail or succeed. It appears >that the Europeans on the standardization committee think it should >succeed: in "Edinburgh" systems it fails. I am embarassed to say that the Melbourne group only discovered this last year. In MU-Prolog and (still) in NU-Prolog (fail -> xyz) succeeds (I hope this will be changed to the standard behaviour some day). I suggest that people using {MN}U-Prolog avoid using -> without the else part. While I think its not such a good idea to change the "standard" behaviour at this stage, I think the whole construct must have been designed after a good many pints of 70 shilling on Grassmarket: 1) -> in logic means implication, or if-then, so the syntax is suggestive of logic. However, in logic false->xyz is true! 2) Making -> fail when the condition fails make -> without ; virtually useless. a->b is the same as once(a),b which is much more clear. The only common use is (a->b;c->d;otherwise->e), which behaves the same way with either semantics for ->. Also if -> succeeded when the condition failed "otherwise->" could be dropped, making the code simpler and more efficient. 3) With the non-standard semantics -> is very useful for checking error conditions and other exceptions: (var(X) -> error("Nonvar expected")),... 4) Why use ; for else? It overloads ; and makes its definition (which could be nice, simple and logical) into a non-logical mess (remember that a->b;c is ((a->b);c)). 5) What is cut meant to do inside a condition? This is a great way to break Prolog systems and when -> was defined the use or scope of ! inside contitions should have been restricted (the problem is that the -> creates a choice point, ! removes it, then -> tries to cut back to it). Lee Naish