bugGNU Prolog for Java - Bugs: bug #32560, Problem with retract and assertz

 
 

bug #32560: Problem with retract and assertz

Submitter:  None
Submitted:  Mon 21 Feb 2011 05:25:13 PM UTC
   
 
Category:  Standards Compliance Severity:  3 - Normal
Item Group:  None Status:  Works For Me
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 06 May 2011 08:02:49 AM UTC, comment #6: 

The bug in your code is that you are not doing:
environment.runInitialization(interpreter);
after running ensureLoaded. If you do this then your code will execute as expected.

(the code in question was provided via separate email and is:
Environment environment;
Interpreter interpreter;
  environment = new
Environment();                  environment.ensureLoaded(AtomTerm.get("src/brain/"+files[i]+""));              
                interpreter = environment.createInterpreter();
Term[] args = {new IntegerTerm(10)} ;
CompoundTerm goalTerm = new CompoundTerm(AtomTerm.get("test"), args);
Goal goal = interpreter.prepareGoal(goalTerm);
interpreter.execute(goal);

Daniel Thomas <drt24>
Group administrator
Thu 05 May 2011 04:43:04 PM UTC, comment #5: 

ok, now I explain my problem.
if I paste this on Gnu Prolog shell :

asserta(iola(10)),iola(Z),retract(iola(_)),iola(Q),write(Q).

Prolog say no, and it's correct because the retract remove all iola predicates, also iola(Z); so iola(Q) fails.

If I do this from Java code, I get 10, and this because between iola's asserta and his retract I call iola(Z).
The complete java code is:
Term[] args = new IntegerTerm(10)} ;
CompoundTerm goalTerm = new CompoundTerm(AtomTerm.get("test"), args);
Goal goal = interpreter.prepareGoal(goalTerm);
interpreter.execute(goal);

and test is:

test(X) :- asserta(iola(10)),iola(Z),retract(iola(_)),iola(Q),write(Q).

What's wrong in my method?

Nicola <sandycs>
Fri 01 Apr 2011 08:53:37 AM UTC, comment #4: 

We have added some tests based on your report and they are all working correctly.
Are you sure that you are using 0.2.6? This was a bug that was in 0.2.5 and was fixed in 0.2.6.

Daniel Thomas <drt24>
Group administrator
Mon 28 Feb 2011 09:31:13 AM UTC, comment #3: 

assertz(res(100)),writeRes,retract(res(_)),assertz(res(200)),res(X),write(X).

writeRes :- res(X), write(X).

Anonymous
Wed 23 Feb 2011 09:51:35 AM UTC, comment #2: 

The problem occurs if between assert and retract you invoke a rule using the variable that has been asserted.


Anonymous
Tue 22 Feb 2011 05:45:06 PM UTC, comment #1: 

Bugs like this should have been fixed in 2.6 so I am concerned that it appears that they are not.

I tried

 testassertz :- assertz(res(a)), retract(res(_)), assertz(res(b)), listing(res), res(Z), write(Z).

At the bottom of your attached pana.txt and ran it using GoalRunner but I got:

res(b) :- true.

b

Which is the expected output. Please could you give the exact sequence of instructions which causes this bug to manifest itself.

Thank you,

Daniel

Daniel Thomas <drt24>
Group administrator
Mon 21 Feb 2011 05:25:13 PM UTC, original submission:  

Hello, i found a BUG using gnuprologjava 2.6.
I have a rule that assert a fact names res(X); later I retract it and assert new one(Y is X*2,assertz(res(Y))).
When I write "listing(res)" I have the correct value of res (that is X*2), but if I do res(Z),write(Z) i have the old value of res, X and not Y.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #22748:  pana.txt added by None (380B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by sandycs (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-05-06 drt24 Open/ClosedOpen Closed
    2011-04-01 drt24 StatusIn Progress Works For Me
    2011-03-31 drt24 StatusNeed Info In Progress
    2011-02-22 drt24 CategoryNone Standards Compliance
        StatusNone Need Info
    2011-02-21 None Attached File- Added pana.txt, #22748

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code