Re: Ann: SWI-Prolog 7.1.0

Boris Vassilev <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAFw8osLbSS3YiUcNx7Qhe80yFXiNU6PO3MoFkHss7stRL0w+WA@mail.gmail.com>
Hello,

If I understand correctly Jan's response, if we have a definition like:

foo(A, B, Result) :-
    integer(A),
    integer(B),
    A >= B,
    do_something(A, B, Result).

then it is possible to know at compilation time that neither `integer` nor
`>=` would further instantiate the variables A and B. Furthermore, this
applies recursively to user-defined predicates that do not further
instantiate their arguments, based on their subgoals. Or, in other words,
clauses would be mutually exclusive up to the first subgoal that cannot be
statically determined not to instantiate the arguments in the head of the
clause, or have side effects.

Would it be possible to do this? Especially if predicates like `dif/2` can
be used like this, this sounds very attractive.

What am I missing?
Boris


On Sat, Dec 7, 2013 at 4:51 PM, Jan Wielemaker <[email protected]> wrote:

> 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
>
>
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.