info-gnuprologjava
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Info-gnuprologjava] GPJ gives different results than GNU-Prolog


From: Daniel Thomas
Subject: Re: [Info-gnuprologjava] GPJ gives different results than GNU-Prolog
Date: Sat, 15 Sep 2012 11:46:07 +0100

Hmm slightly confused as the more minimal test case works fine for me
though the original one fails:

$ java -jar '/home/daniel/dev/gnuprolog/releases/0.2.6/gnuprologjava-0.2.6.jar' 
test.pl "run"
GNU Prolog for Java (0.2.6) Goal runner (c) Constantine Plotnikov, 1997-1999.
subs is able to create cert(subs) and to send it to subsender
subs can send message subscriptionConfirmation to subsender
subsender can send cert(subs) to sender
subsender can send message create to sender
time = 48ms

SUCCESS. redo (y/n/a)?y
subsender can send cert(subs) to sender
gnu.prolog.vm.PrologException: error(existence_error(procedure,msg / 6),error)
[snip stacktrace]

The existence_error is to be expected as the reduced test case is
missing msg/6 and GNU Prolog gives the same result:
$ gprolog
GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?- [test].
compiling /home/daniel/dev/gnuprolog/support/cheung/test.pl for byte
code...
/home/daniel/dev/gnuprolog/support/cheung/test.pl compiled, 46 lines
read - 5902 bytes written, 14 ms

(4 ms) yes
| ?- run.
subs is able to create cert(subs) and to send it to subsender
subs can send message subscriptionConfirmation to subsender
subsender can send cert(subs) to sender
subsender can send message create to sender

true ? ;
subsender can send cert(subs) to sender
uncaught exception: error(existence_error(procedure,msg/6),(\+)/1)

I recall fixing some bugs with dynamic predicates for the 0.2.6 relase.
Burak Emir: are you using 0.2.6?


I put some more debugging into sendCert to give:
sendCert(Sender, Receiver, Cert):-                      
        write('seeing if have cert: '),write(Sender),write(',
'),write(Cert),write('\n'),write('certs:'),findall(hasCert(X,Y),hasCert(X,Y),List),write(List),write('\n'),
        hasCert(Sender, Cert),write(hasCert(Sender,Cert)),write('\n'),
        assert(hasCert(Receiver, Cert)),
        write(Sender), write(' can send '), write(Cert), 
     write(' to '), write(Receiver), write('\n').
as the first predicate of sendCert

This gives the illuminating output:
seeing if have cert: subsender, cert(subs,null,perm(fors,forward),null,-1,-1)
certs:[hasCert(subs,cert(subreceiver,null,perm(receiver,receive),null,-1,-1)), 
hasCert(subsender,cert(subs,null,perm(fors,forward),null,-1,-1))]
ERROR: subsender is not able to send 
cert(subs,null,perm(fors,forward),null,-1,-1) to sender

Which indicates that hasCert(Sender, Cert) is failing even though
findall(hasCert(X,Y),hasCert(X,Y),List) finds something which is at
least textually equivalent to hasCert(Sender, Cert).

So yes looks like a bug, some sort of incorrect caching of what
predicate exist or similar, unfortunately it looks to be a more subtle
flaw than the one fixed in 0.2.6 as we have simple test cases that
assert something and then check that it exits.
Assistance with finding a minimal test case greatly appreciated as
presently it is rather difficult to debug where things are going wrong.

Daniel

On Thu, 2012-09-13 at 03:00 +0200, John Cheung wrote:
> Hello,
> 
> first thank you for your answer. You could be right.
> There could be a problem with dynamic(hasCert/2),
> but does GPJ not supports the dynamic command?
> 
> John C.
> 
> -----Ursprüngliche Nachricht----- 
> From: Burak Emir
> Sent: Wednesday, September 12, 2012 11:49 PM
> To: John Cheung
> Cc: address@hidden
> Subject: Re: [Info-gnuprologjava] GPJ gives different results than 
> GNU-Prolog
> 
> P.S. I have reduced it to the following.
> I guess one can reduce it further.
> Could it be that something is wrong with the dynamic(hasCert/2) ?
> 
> -- Burak
> 
> /// code:
> 
> msg(2, subs, subsender, 'subscriptionConfirmation', [cert(subs)] ).
> msg(3, subsender, sender, 'create', [cert(subs)] ).
> 
> :- dynamic(hasCert/2).
> 
> sendCert(Sender, Receiver, Cert):-
>         hasCert(Sender, Cert),
>         assertz(hasCert(Receiver, Cert)),
>         write(Sender), write(' can send '), write(Cert),
>      write(' to '), write(Receiver), write('\n').
> 
> sendCert(Sender, Receiver, cert(Sender)):-
>         assertz(hasCert(Receiver, cert(Sender))),
>         write(Sender), write(' is able to create '),
>         write(cert(Sender)),
>         write(' and to send it to '), write(Receiver), write('\n').
> 
> sendAllCerts(_, _, _, []).
> 
> sendAllCerts(Step, From, To, [F_Cert|Rest]):-
>         sendCert(From, To, F_Cert),
>         sendAllCerts(Step, From, To, Rest).
> 
> sendAllCerts(Step, From, To, [F_Cert|Rest]):-
>         \+(sendCert(From, To, F_Cert)),
>         sendAllCerts(Step, From, To, Rest),
>         write('ERROR: '),
>         write(From), write(' is not able to send '),
>         write(F_Cert), write(' to '),
>         write(To), write('\n').
> 
> run(Step, MaxSteps):- Step < MaxSteps,
>         msg(Step, Sender, Receiver, Name , C_List),
>         sendAllCerts(Step, Sender, Receiver, C_List),
>         write(Sender), write(' can send message '),
>         write(Name), write(' to '), write(Receiver), write('\n'),
>         IPlus1 is Step + 1, run(IPlus1, MaxSteps).
> 
> run(Step, MaxSteps):-
>         Step < MaxSteps,
>     \+(msg(Step, _, _, _, _,_ )),
>         IPlus1 is Step + 1, run(IPlus1, MaxSteps).
> 
> run(MaxSteps, MaxSteps).
> 
> run:-run(2,4).
> 
> /// GPJ output:
> subs is able to create cert(subs) and to send it to subsender
> subs can send message subscriptionConfirmation to subsender
> ERROR: subsender is not able to send cert(subs) to sender
> subsender can send message create to sender
> 
> /// GNU Prolog output:
> subs is able to create cert(subs) and to send it to subsender
> subs can send message subscriptionConfirmation to subsender
> subsender can send cert(subs) to sender
> subsender can send message create to sender
> 
> 
> 
> On Wed, Sep 12, 2012 at 7:33 PM, Burak Emir <address@hidden> wrote:
> > Hey John,
> >
> > Looks interesting, probably a bug!
> >
> > Your example is still quite long though - is it possible to find a
> > smaller program that still produces two different results?
> >
> > At the risk of stating the obvious, having the shortest program
> > possible makes it much easier to debug.
> >
> > -- Burak Emir
> >
> > On Tue, Sep 11, 2012 at 3:19 PM, John Cheung <address@hidden> 
> > wrote:
> >> Hello,
> >>
> >> i'm trying to run my prolog programm from Java with GPJ.
> >>
> >> The programm gives the correct result in GNU-Prolog, but GNU Prolog for 
> >> Java
> >> gives another
> >> result. Can it be that GNU Prolog supports more or other commands than 
> >> GPJ?
> >> I don't see what's causing this problem.
> >>
> >>
> >> I've attached the program and the different results for you. You can 
> >> start
> >> the Programm by
> >> invorking "run." .
> >>
> >> I need this for my thesis, so I would be very grateful if you could help 
> >> me.
> >>
> >> Thank You,
> >>
> >> John C.
> >
> >
> >
> > --
> > Burak Emir
> > --
> > http://burak.emir.googlepages.com
> 
> 
> 

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]