info-gnuprologjava
[Top][All Lists]
Advanced

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

Re: [Info-gnuprologjava] Adding facts to environment dynamicly


From: Daniel Thomas
Subject: Re: [Info-gnuprologjava] Adding facts to environment dynamicly
Date: Sat, 11 Jun 2011 14:32:40 +0100

Hello,

Sorry I was insufficiently clear (and had exams last week so didn't get
back to you earlier) when I said assert[a/z] I meant asserta/assertz in
that assert is not a valid predicate but asserta/1 and assertz/1 are
(see the ISO prolog standard or a textbook).
dynamic is a Directive not a normal predicate (see 7.4.2 Directives in
the standard this should hopefully also be covered in textbooks). If you
are storing predicates across multiple files you will also need to use
multifile/1 as otherwise predicates are restricted to being defined in
only one file.

I hope that helps,

Daniel

On Tue, 2011-06-07 at 16:46 +0200, Dominik Schmeiser wrote:
> Hi Daniel,
> 
> thanks for your quick reply.
> 
> Unfortunately it still does not work. We have two Prolog-Files.
> 
> File 1:
>  foo(bar1).
> 
> File 2:
>  :- dynamic(foo/1).
>  invoke(R) :- assert[a/z](foo(bar2)).
> 
> Both files are loaded to the environment (using
> environment.ensureLoaded(AtomTerm.get(<path>))) and we have still an
> existence error for "assert" and the permission error for asserta & -z when
> we try to use invoke.
> We were not sure if the dynamic-predicate is really used, so we extended
> the file to
> 
> invokeD(R) :- dynamic(foo/1).
> 
> When we then called the invokeD we got an existence-error, too:
> gnu.prolog.vm.PrologException: error(existence_error(procedure,dynamic /
> 1),error)
> 
> We're using verion 0.2.6.
> 
> We looked through some bug reports and found minimal examples like this:
> :- dynamic(aFoo/1).
> :- initialization(assertz(aFoo(1)),aFoo(1),assertz(aFoo(2)),aFoo(2)).
> 
> Our experience implies that this - especially the ":-
> dynamic(aFoo/1)."-part - works not in our environment.
> Is there probably something we're missing in our Java-code?
> 
> environment = new Environment();
> environment.ensureLoaded(AtomTerm.get(<path1>));
> environment.ensureLoaded(AtomTerm.get(<path2>));
>               
> interpreter = environment.createInterpreter();
> environment.runInitialization(interpreter);
> 
> VariableTerm v = new VariableTerm("vTerm");
> Term[] a = {v};
> CompoundTerm c = new CompoundTerm("invoke", a);
>                       
> Interpreter.Goal goal = interpreter.prepareGoal(c);
> int result = interpreter.execute(goal);
> 
> We really have no idea where we're going wrong.
> 
> Thanks for your time and help! :-)
> 
> Dominik
> 
> 
> On Mon, 06 Jun 2011 13:20:40 +0100, Daniel Thomas <address@hidden> wrote:
> > Hello,
> > 
> > Before you can use assert[a,z] on a predicate you first need to declare
> > it to be dynamic e.g.
> > :- dynamic(foo/1).
> > 
> > I hope that helps,
> > 
> > Daniel
> > 
> > On Sun, 2011-06-05 at 14:32 +0200, Dominik Schmeiser wrote:
> >> Hi all,
> >> 
> >> Me and my collegue are working with GPJ on an project for the
> > university.
> >> we have a Prolog-Environment which already loaded some facts. (using
> >> environment.ensureLoaded(...))
> >> 
> >> e.g.
> >> foo(bar1).
> >> foo(bar2).
> >> 
> >> Now we try to invoke a rule (using interpreter.execute(...)).
> >> This rule should create some new facts in the environment,
> >> 
> >> e.g.
> >> invoke :- assert( foo(bar3) ).
> >> 
> >> Our problem:
> >> When we use the predicate "assert" t is not recognized:
> >> - gnu.prolog.vm.PrologException: error(existence_error(procedure,assert
> > /
> >> 1),error)
> >> When we try "asserta" or "assertz" we have another error that implies we
> >> would like to override the facts which are already in the environment:
> >> - gnu.prolog.vm.PrologException:
> >> error(permission_error(modify,static_procedure,foo / 1),error)
> >> 
> >> Our question:
> >> Is there any possibility to add facts to the environment dynamicly?
> >> 
> >> Please note that I'm not on the mailing list so please reply directly.
> >> 
> >> TIA
> >> 
> >> Dominik
> >> 
> >> 
> >> 
> >> 
> 

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


reply via email to

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