2

Say I am listing facts:

letter(a).
letter(b).
letter(c).
...
letter(z).
vowel(a).
consonant(b).
consonant(c).
consonant(d).
vowel(e).
consonant(f).
...
consonant(z).

If I declare the rules in 'alphabetical' order, I get the following warnings in the console:

Warning: /Users/…/prolog-example.pl:31:
  Clauses of vowel/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:32:
  Clauses of consonant/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:35:
  Clauses of vowel/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:36:
  Clauses of consonant/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:51:
  Clauses of vowel/1 are not together in the source-file

But if I do the following:

letter(a).
letter(b).
letter(c).
...
letter(z).
consonant(b).
consonant(c).
consonant(d).
...
consonant(z).
vowel(a).
vowel(e).
vowel(i).
vowel(o).
vowel(u).
vowel(y).

I dont get the warnings. Are the warnings just warnings or are they actual errors?

false
  • 10,264
  • 13
  • 101
  • 209
chris Frisina
  • 19,086
  • 22
  • 87
  • 167

3 Answers3

4

When a predicate definition is discontiguous, the predicate should be declared as such using the standard discontiguous/1 directive before its clauses. In your case:

:- discontiguous([
    letter/1,
    vowel/,
    consonant/1
]).

If you have discontiguous predicates without corresponding discontiguous/1 directives, the consequences depend on the used Prolog system. For example, SWI-Prolog and YAP will print warnings but accept all clauses. GNU Prolog will ignore clauses. ECLiPSe will report a compilation error. In the case the Prolog system doesn't throw an error, a warning is usually still printed as a predicate may be detected as discontiguous due to e.g. a simple typo in a clause head.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
2

They are just warnings on some systems. This is to prevent you from accidentally adding clauses to a predicate when you wanted to write a new one. You can get rid of those in SWI (the messages look like the ones you get from SWI, and I haven't used other dialects too much).

You can either use style_check/1, or the discontiugous directive.

:- discontiguous vowel/1,consonant/1,letter/1.
% alternative:
:- style_check(-discontiguous).
Patrick J. S.
  • 2,885
  • 19
  • 26
2

The standard ISO/IEC 13211-1:1995 reads on this:

7.4.3 Clauses

...

All the clauses for a user-defined procedure P shall be
consecutive read-terms of a single Prolog text unless there
is a directive discontiguous(UP) directive indicating P in that Prolog text.

So the standards demands (»shall«) that all clauses are consecutive by default. A programmer or program that now relies on the clauses being added nevertheless does not rely on standard behavior.

false
  • 10,264
  • 13
  • 101
  • 209