Re: Ann: SWI-Prolog 7.1.0
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 12/07/2013 12:11 PM, Paulo Moura wrote: > But there's an important difference here that is not apparent if a switch-on-tag would solve. Often, you have something like: > > do(X) :- atom(X), !, .... > do(X) :- number(X), !, ... > do(X) :- string(X), !, ... > > Does the approach you mention avoids creating a choice-point for do(X) calls that is then discarded by the cuts? The advantage (I observed) of the alternative solution: > > do(atom(X)) :- > do(number(X)) :- > do(string(X)) :- All you need is a compiler that decides at compile time that the clauses are mutually exclusive. That can be done just as well for the first set (even without the cuts) as for the second. I'm sure some people on this list can point at Prolog implementations that do this. Surely, this can be implemented pretty trivially in SWI-Prolog's just-in-time indexing scheme. It merely consists of adding an additional detector for this type of switch, which will be called the first time the predicate is called. > is that no choice-point is created for calls to do(X) where X is instantiated. Plus, from my readings about Prolog implementations, those that do a switch-on-tag approach do so only when the tests are the standard *built-in* term type predicates, which doesn't help with the also common cases where the tests are calls to user-defined predicates. Of course, if you put user code in between, it will become increasingly more complicated. Cheers --- Jan