User defined arithmetic behaves differently on interactive level

Steve Moyle <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
I am porting something that runs on Yap and am getting issues with the run time execution of the definition of an arithmetic function.  It behaves as desired at the interactive level but not when run inside a program.

Here is the test code that illustrates the issue.

:- use_module(library(arithmetic)).
:- arithmetic_function(inf/0).

inf(1e10).

label([5, 0, 4, 5]).
label1([-inf, 0, 1, -inf]).

test :-
    label(Label),
    label1(Label1),
    Label = [_,_,L,Gain|_],
    Label1 = [_,_,L1,Gain1|_],
    (   inf> -inf -> writeln('Works'); writeln('No worky')), % Test inf arithmetic is working
        ((Gain> Gain1);(Gain =:= Gain1, L < L1)), !.

Here is it being run.  


$ swipl -s inf.pl
%   library(error) compiled into error 0.00 sec, 81 clauses
%   library(lists) compiled into lists 0.00 sec, 95 clauses
%  library(arithmetic) compiled into arithmetic 0.01 sec, 285 clauses
%  .../inf.pl compiled 0.01 sec, 294 clauses
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.3.3-17-gf077dc2)
Copyright (c) 1990-2012 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- test.
Works
ERROR:>/2: Arithmetic: `inf/0' is not a function
?- 5> -inf.
true.


At the point where the error occurs the variables Gain and Gain1 are bound to 
5 and inf/0 respectively.  The system should be evaluating 5> -inf at that point.

Such a test succeeds (5> -inf.) on the interactive level which is the desired behaviour, but not in program execution.

Any help appreciated.

Thanks,

Steve
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.