[eclipse-clp-users] Retract/asserta in C++

From: Christian Giffhorn <chrgiffhorn_at_gmail.com>
Date: Mon, 23 Apr 2012 11:17:39 +0200
I have problems, to edit my knowledge base from c++ side. The first
addition with "asserta" still works, but it behave like an "assert"
because even when the retract didn't work, it should use the newest
entry from the "asserta" like when i use asserta in the eclipse tk.

i give you an short example of the code i am using. And ask for help
where i made the mistake, or how could i make it better.

:- discontiguous(tool/3).
:- dynamic tool/3.

% rules set etc.

EC_word asserta(EC_word fact)
	return term(EC_functor("asserta", 1), fact);

EC_word removefact(EC_word fact)
	return term(EC_functor("retract", 1), fact);
} // you should be concrte with your fact here, for the case that you
only more then one target fitting this criteria, it will take the

for (int i = 0; i < 3; i++)
   sprintf (randomv, "%i", rand() % 8 + 1);

   post_goal(asserta(term(EC_functor("tool", 3), EC_atom("hammer"),
EC_atom(randomv), EC_atom("s0"))));

   post_goal(run(EC_atom("control"), EC_atom("s0"), p));

   post_goal(removefact(term(EC_functor("tool", 3), EC_atom("hammer"),
EC_atom(randomv), EC_atom("s0"))));

Received on Mon Apr 23 2012 - 09:17:52 CEST

This archive was generated by hypermail 2.2.0 : Thu Apr 26 2012 - 06:17:39 CEST