I am new to prolog.
I read this article about structures in Prolog. However, the following code does not work:
<code>is_point(point1,point(5,7)).
test0:-is_point(point1,X),test1(X).
test1(X):X=point(OX,OY),OX=5.
test2:-test1(point(5,8)).
somepoints([ point(5,6), point(5,10)]).
test3:-somepoints(L),L is [X|_],test1(X).
</code>
<code>is_point(point1,point(5,7)).
test0:-is_point(point1,X),test1(X).
test1(X):X=point(OX,OY),OX=5.
test2:-test1(point(5,8)).
somepoints([ point(5,6), point(5,10)]).
test3:-somepoints(L),L is [X|_],test1(X).
</code>
is_point(point1,point(5,7)).
test0:-is_point(point1,X),test1(X).
test1(X):X=point(OX,OY),OX=5.
test2:-test1(point(5,8)).
somepoints([ point(5,6), point(5,10)]).
test3:-somepoints(L),L is [X|_],test1(X).
The query ? is_point(point1,X).
does work. Also ? some_points(L).
but launching ? test0.
, ? test2.
or test3.
gives approximately the same error, which is
<code>14 ?- test0.
ERROR: Unknown procedure: test1/1
ERROR: However, there are definitions for:
ERROR: test0/0
ERROR: test2/0
ERROR: test3/0
ERROR:
ERROR: In:
ERROR: [13] test1(point(5,7))
ERROR: [11] toplevel_call(user:user:test0) at c:/software/msys64/mingw64/lib/swipl/boot/toplevel.pl:1317
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
Exception: (13)
[[ EXCEPTION while printing message '~W'
with arguments [test1(point(5,7)),[max_depth(3.4848e-319),quoted(true),portray(true),attributes(portray),spacing(next_argument)]]:
raised: type_error(integer,3.4848e-319)
]]
</code>
<code>14 ?- test0.
ERROR: Unknown procedure: test1/1
ERROR: However, there are definitions for:
ERROR: test0/0
ERROR: test2/0
ERROR: test3/0
ERROR:
ERROR: In:
ERROR: [13] test1(point(5,7))
ERROR: [11] toplevel_call(user:user:test0) at c:/software/msys64/mingw64/lib/swipl/boot/toplevel.pl:1317
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
Exception: (13)
[[ EXCEPTION while printing message '~W'
with arguments [test1(point(5,7)),[max_depth(3.4848e-319),quoted(true),portray(true),attributes(portray),spacing(next_argument)]]:
raised: type_error(integer,3.4848e-319)
]]
</code>
14 ?- test0.
ERROR: Unknown procedure: test1/1
ERROR: However, there are definitions for:
ERROR: test0/0
ERROR: test2/0
ERROR: test3/0
ERROR:
ERROR: In:
ERROR: [13] test1(point(5,7))
ERROR: [11] toplevel_call(user:user:test0) at c:/software/msys64/mingw64/lib/swipl/boot/toplevel.pl:1317
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
Exception: (13)
[[ EXCEPTION while printing message '~W'
with arguments [test1(point(5,7)),[max_depth(3.4848e-319),quoted(true),portray(true),attributes(portray),spacing(next_argument)]]:
raised: type_error(integer,3.4848e-319)
]]
So what is the correct syntax to work with structures in Prolog?