0

I am attempting to run an example GNU Prolog program used as an example during my course work. The code is pulled directly from https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_17pl.txt and was shown working at one point by my professor.

However, when I run the provided example code, I get the following compilation warning:

| ?- consult('C:/Users/Chase/Desktop/Prolog files/newAnimal.pro').
compiling C:/Users/Chase/Desktop/Prolog files/newAnimal.pro for byte code...
C:/Users/Chase/Desktop/Prolog files/newAnimal.pro:74:12: syntax error: . or operator expected after expression
    1 error(s)
compilation failed

The line that is keeping the program from compiling correctly is:

:- dynamic yes/1,no/1.

Which I read up on here: https://www.swi-prolog.org/pldoc/man?predicate=dynamic/1

However, despite attempting to rewrite and reformat the section, I could still not get it to compile.

Any help on why the provided code may not be running?

I am using a Windows GUI GNU Prolog console V1.4.5

false
  • 10,264
  • 13
  • 101
  • 209
Xlite
  • 5
  • 1
  • 2
  • 2
    I think that ```dynamic``` is not an operator in Gnu-Prolog, try to use ```:- dynamic([yes/1, no/1]).``` or ```:- dynamic(yes/1), dynamic(no/1).```. – slago Feb 24 '21 at 03:14

1 Answers1

2

The ISO Prolog standard doesn't require dynamic(or multifile or discontiguous) to be declared as an operator. A few systems do it (e.g. SWI-Prolog like you mentioned) but not GNU Prolog. Thus, to ensure code portability, avoid using dynamic as an operator. Write instead:

:- dynamic(yes/1).
:- dynamic(no/1).

Or:

:- dynamic((yes/1, no/1)).

Or:

:- dynamic([yes/1, no/1]).

These are the standard conforming alternatives for declaring multiple predicates as dynamic.

Also, GNU Prolog have a fine manual (part of its installation) which you should refer to when using GNU Prolog.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • Exactly what was wrong, thank you very much for the insight! – Xlite Feb 24 '21 at 13:39
  • Given that `dynamic` is not declared as an operator in GNU Prolog, there can be no space between the atom `dynamic` and the directive arguments. – Paulo Moura Feb 24 '21 at 14:03