prologagentmulti-agent

How to reverse or construct a belief in jason (agentspeak)?


I would like to do the following:

I have a initial goal with an argument as a belief, and I would like to reverse it, so that the belief's argument becomes the new belief, and the argument becomes the beliefname.

Something like this:

//Agent asker in project Test.mas2j
!translate(barks(dog)). //I would like to have the belief: dog(barks)
+!translate(T)<-
    T =.. [A,[B],C];
    .print("functor: ",A);
    .print("argument: ",B);
    //.print("source: ",C);
    +B(A);//<- I want something like this, but it gives a syntax error.
    +B. //<-this works, but it doesn't give the argument to it

So, my question is, hogy to constract beliefs in this way?


Solution

  • Construct the term like you do for T:

    ...
    X =.. [B,[A]]; // constructs the belief
    +X; // adds the belief to the current belief base
    ...
    

    From the book Programming Multi-Agent Systems in AgentSpeak using Jason:

    One operator also available in Prolog that works slightly differently here (because of the predicate annotations not available in Prolog) is ā€˜=..ā€™, which is used to deconstruct a literal into a list. The resulting list has the format [functor, list of arguments, list of annotations], for example: p(b,c)[a1,a2] =.. [p, [b,c], [a1,a2]].