info-gnuprologjava
[Top][All Lists]
Advanced

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

Re: [Info-gnuprologjava] PrologCode.SUCCESS_LAST ¿bug?


From: Juan Galán Páez
Subject: Re: [Info-gnuprologjava] PrologCode.SUCCESS_LAST ¿bug?
Date: Mon, 4 Jun 2012 16:13:22 +0200

Thanks Daniel

Finally I have implemented a dirty fix, because later I found different behaviors when reading the last result.
Every time user ask for the next solution (lets say N), I return the solution N (previously stored) and compute N+1 and store it. In this way i can capture the exception when there are no more solutions and manage it properly. It isn't fancy but works :)

Any way I tell you what i found, so if it can be useful for you.
May be there are more cases where it can arises, but here are two:

1) I keep executing, until i read the last 'valid solution' and always getting PrologCode.SUCCESS. After if I execute one more time I get HALT/FAIL code and if you try to dereference, lets say 'var X' you get the symbol 'X'. So in this case it is nice because I can do a final execution where i get HALT/FAIL and I can manage the end of the execution properly.

2) Second case is more tricky. I don't know if this happens in more situations, but here is an example:

I load a file with

...
fact(1).
fact(2).
fact(3).
fact(4).
...

Then I ask fact(X).
So I get
1
2
3
4
Always returning SUCCESS code.
But in the next execution instead of getting a HALT/STOP code as before, an exception is raised telling that there is no active goal. So I don't have the chance to detect that there are no more solutions until the exception is raised, and with this, the execution is interrupted. This is the reason why I am using the exception as Stop code in every case.

But anyway my problem is solved for the time being.
Thakns again
Juan Galan


2012/6/2 Daniel Thomas <address@hidden>
Hello Juan,

Sorry for the delay in getting back to you about this. Having looked
into it, it does seem that this is definitely a problem that is
occurring. However I am not sure whether this is a bug or not, it
depends whether prolog should be able to tell that there are more
possible solutions or not. I think I get the same behaviour in SWIProlog
so perhaps this is what is supposed to happen.

Unfortunately working out exactly where GPJ thinks there are more
solutions when there are none is difficult as this is all done inside
the Warren abstract machine by the InterpretedByteCode class which is
rather hairy and which I don't understand fully. I tried stepping
through it but it is hard to see the wood from the trees.

Sorry I can't be more helpful.

Daniel

On Wed, 2012-05-09 at 12:08 +0200, Juan Galán Páez wrote:
> Hi
>
> Congrats again por the project.
> I wrote here last year, but my project has been stopped until now. I
> took it again in the last weeks and the first alpha version is relesed
> (http://www.cs.us.es/~fsancho/NetProLogo/?p=about). It is a extension
> por NetLogo (a popular agent based modeling platform), your library
> was really helpful for this task.
>
> I have the following problem.
>
> I need somehow to know if there are reminning solutions to read when
> executing a query. I think it would be possible to solve this in a
> tricky way by previously computing and storing the solution to be
> returnet in a future call, but i preffer to avoid this.
> I have been playing a bit with the codes returned by 'execute' and i
> never get 'PrologCode.SUCCESS_LAST' (1). I just get
> 'PrologCode.SUCCESS' (0) and when there aren't more solutions
> 'PrologCode.FAIL' (-1). So, am I doing something wrong? or is it a
> bug? is there any alternative?, i suppose it does'nt exist something
> like '<boolean> hasMoreSolutions(goal)'.
>
> To show an example, here is a simple case:
>
> PROLOG CODE:
>
> permutation([],[]).
> permutation(L1,[X|L2]) :-
>              select1(X,L1,L3),
>              permutation(L3,L2).
>
> select1(H,[H|T],T).
> select1(X,[H|T],[H|T1]) :- select1(X,T,T1).
>
> PROLOG CALL:
>
> permutation([a,b,c],L)
>
> OUTPUT(last lines):
>
> 4 Code: 0
> [c,a,b]
> 5 Code: 0
> [c,b,a]
> 6 Code: -1
> L
>
> Thank you
> Juan Galan



reply via email to

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