Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uunet!in1.uu.net!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!conway
From: conway@munta.cs.mu.OZ.AU (Thomas Charles CONWAY)
Subject: Indexing (was Re: Help!! union without cut!?)
Message-ID: <9510618.27288@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <3ldruq$fka@cpccux0.cityu.edu.hk> <3lejg1$djm@irix.uci.kun.nl> <3lo84f$4rk@goanna.cs.rmit.edu.au> <HSCHOTEL-0304951429060001@atdmac10.let.kun.nl> <3m34ll$304@gaudi.ac.upc.es> <3mfo2q$jc@goanna.cs.rmit.edu.au>
Date: Sun, 16 Apr 1995 08:57:14 GMT
Lines: 41

ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) writes:

>(3) Of these two versions, which one does not benefit from first-argument
>    indexing and which one does, and why does this matter?  (This is a
>    different question from _SHOULD_ it matter; I imagine we all agree that
>    it shouldn't.)

I am curious to know why most Prolog implementations has such
dismal indexing (usually limited to top functor, first argument)
when indexing has such a big impact on performance. Why do
implementations not provide indexing at least on the top level
functors of all head arguments?

In the Mercury implementation we merge the multiple clauses of a
predicate into a single clause with an explicit disjunction
(eg
p([], 0).
p([X|Xs], Sum) :-
	p(Xs, Sum0),
	Sum is Sum0 + X.
becomes
p(H1, H2) :-
	(
		H1 = [],
		H2 = 0
	;
		H1 = [X|Xs],
		H2 = Sum,
		p(Xs, Sum0),
		Sum is Sum0 + X
	).
).

We then do indexing on all disjunctions. This means that where
Prolog programmers will often introduce a small auxiliary
predicates to get better indexing, Mercury programmers can mostly
use an explicit disjunction. This removes the need for the
overhead of a predicate call, and often results in better
readability of code.

Thomas
