Question

Given the following code:

example1(X) :- X is 1.
example2(X) :- X is 1+1.

when I run it with gprolog, I get:

$ gprolog 
GNU Prolog 1.4.0
By Daniel Diaz
Copyright (C) 1999-2011 Daniel Diaz
| ?- ['example'].
compiling /Users/tomo/projects/7L7W/prolog/day2/example.pl for byte code...
/Users/tomo/projects/7L7W/prolog/day2/example.pl compiled, 1 lines read - 490 bytes written, 7 ms

(1 ms) yes
| ?- example1(X).

X = 1

yes
| ?- example2(X).

Fatal Error: Segmentation Violation

However, if I compile the file:

$ gplc example.pl -o example
$ ./example 
GNU Prolog 1.4.0
By Daniel Diaz
Copyright (C) 1999-2011 Daniel Diaz
| ?- example1(X).

X = 1

yes
| ?- example2(X). 

X = 2

yes

What am I missing? Why it segfaults in the first case and runs OK in the second?

(If it helps: Mac OS 10.7.2)

Was it helpful?

Solution

That's probably a bug in gprolog. Just report it.

Also, you may prefer to use SWI-Prolog that is quite more popular and supported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top