Next: Example 1
Up: No Title
Previous: No Title
- Prolog does backtracking by default - this is good
- but in certain scenarios it is more efficient to avoid it
- Improves program efficiency and performance
- Ability to control backtracking in situations when it is
not really needed
- This is done via a metalevel predicate called the
cut
- Affects procedural behaviour of programs by pruning
the search tree
- it's use is highly controversial (from software engineering
point of view) - as it diminishes the declarative style encouraged
by logic programming
- however, widely used - as can greatly improve efficiency
member(X, [ X| _]) :- !.
member(X, [ _| Tail) :-
member( X, Tail).
Notice the use of the cut in the first clause
Omer F Rana
Sun Feb 16 21:01:24 GMT 1997