Article View: comp.lang.prolog
Article #48CUT in procedural applications
From: Glenn Holliday
Date: Tue, 03 Nov 1992 15:27
Date: Tue, 03 Nov 1992 15:27
32 lines
1938 bytes
1938 bytes
Question of style for finished applications in Prolog. What is
the prevailing opinion/practice for cuts?
It seems to me that applications which do procedural work need a lot more
cuts than the books recommend. I understand why it's a good thing to get rid
of cuts. But most procedural predicates should have guaranteed deterministic
behavior. Cut is the way to guarantee that. For instance,
program :-
getInput(SomeInput),
proveStuffAboutInput(SomeInput, SomeOutput),
writeOutput(SomeOutput).
The non-logical procedures getInput/1 and writeOutput/1, once they are
first satisfied, should never be backtracked into. Assuming each has some
subgoals for which the same thing is true, 2/3 of the program should be
protected by cuts.
Some predicates can be written so that unwanted backtracking will never
match the arguments. The trivial cases of predicates with a single clause,
and the last predicate satisfied, never need cuts. But I believe these cases
are in the minority for procedural code which models lots of if-type choices.
I measured a real application I wrote, with 809 clauses and 491 cuts.
There's probably some room for improvement there, but I think that's in the
ballpark for what this type of application really needs. Am I missing
something, or do Prolog programmers at large find this to be true?
Looking forward to your comments,
--
Glenn Holliday | holliday@csgrad.cs.vt.edu
Technical Details
Message-ID:
<3728@creatures.cs.vt.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!vtserf!creatures!csgrad.cs.vt.edu!hollidayShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!vtserf!creatures!csgrad.cs.vt.edu!holliday From: holliday@csgrad.cs.vt.edu (Glenn Holliday) Newsgroups: comp.lang.prolog Subject: CUT in procedural applications Summary: Don't we really need more CUTs than purity allows? Keywords: Prolog cut choice Message-ID: <3728@creatures.cs.vt.edu> Date: 3 Nov 92 15:27:54 GMT Sender: usenet@creatures.cs.vt.edu Organization: VPI&SU Computer Science Department, Blacksburg, VA Lines: 32