2

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?

Cleber Jorge Amaral
  • 1,316
  • 13
  • 26
Adamsan
  • 662
  • 1
  • 15
  • 27

1 Answers1

3

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]].

ehird
  • 40,602
  • 3
  • 180
  • 182
CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • In the meantime, I've figured it out. Your solution is syntacticly incorrect, but it's pretty close. If you dont mind, I will edit it, then accept it. – Adamsan May 13 '12 at 12:07
  • 1
    Good! I tried the following code which worked very well! !translate(barks(dog)). +!translate(T) <- T =.. [A,[B],C]; X =.. [B,[A]]; +X. – Cleber Jorge Amaral Aug 24 '17 at 23:48