Questions about the output of a simple example on JASON Console

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Questions about the output of a simple example on JASON Console

Development-14
Hello all,

i am a beginner in Agentprogramming and especially in the programming
language Agentspeak of   JASON!
I am reading at the moment Programming Agents using Agentspeak using
Jason Chapther 2.
There is aa example how to cumpute the factorial of a number.

/* Initial beliefs and rules */
fact(0,1).


/* Plans */

+fact(X,Y): X <= 5 <- +fact (X+1, (X+1) *Y);.print("Updating beliefbase
with: fact(",X,",",Y,")").

+fact(X,Y): X == 5<- .print("fact 5 == " ,Y).


the output of the console is :
[factornonrekursive] Updating beliefbase with: fact(4,24)
[factornonrekursive] Updating beliefbase with: fact(3,6)
[factornonrekursive] Updating beliefbase with: fact(2,2)
[factornonrekursive] Updating beliefbase with: fact(1,1)
[factornonrekursive] Updating beliefbase with: fact(0,1)



Question 1: Is Agentspeak a rekursive language ? Because of the "false"=
reverse order of the output?
Question 2: Why does he print fact 5 == 120??  Look at the second plan!  
if i modify the  firstplan to  +fact(X,Y): X *< *5 <- ... he prints !

.
When i modify the code to:

fact(0,1).

/* Initial goals */


/* Plans */

+fact(X,Y): X == 0<- .print("fact 0 == " ,Y).
+fact(X,Y): X < 5 <- +fact (X+1, (X+1) *Y);.print("Updating beliefbase
with: fact(",X,",",Y,")").

he just print [factornonrekursive] fact 0 == 1


Question 3 => so he didn`t do the second plan why ?? (The debugging
method  showing  that the  beliefbase is  just  fact(0,1)


I am a liitle bit confused !! Hopefully you can help me out!


Best regards,
MArtin

 

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users
Reply | Threaded
Open this post in threaded view
|

Re: Questions about the output of a simple example on JASON Console

Rafael H Bordini-2
Hi Martin,

The example in the book has X < 5 in the first plan, not X<=5 but the
only difference is in the type of message printed, for me Jason prints
fact(5,120) too in your first version, not sure why it works differently
for you, if that's the case.

The order of the messages is a simply because of the order in which the
intentions happened to be executed. The default configuration of the
interpreter (which can be changed) is that a belief addition creates a
separate intention although I must say I need to check why the new
intentions are being added at the beginning of the intention "list".

Regarding your question 3: your first plan doesn't add new beliefs so
there are no events for the agent to react to after that.

Note that the factorial example is very artificial, not a usual agent
program, and used in the very beginning of the book just to give a feel
for what the language looks like for those used with traditional
programming languages.

Rafael



Development wrote:

> Hello all,
>
> i am a beginner in Agentprogramming and especially in the programming
> language Agentspeak of   JASON!
> I am reading at the moment Programming Agents using Agentspeak using
> Jason Chapther 2.
> There is aa example how to cumpute the factorial of a number.
>
> /* Initial beliefs and rules */
> fact(0,1).
>
>
> /* Plans */
>
> +fact(X,Y): X <= 5 <- +fact (X+1, (X+1) *Y);.print("Updating beliefbase
> with: fact(",X,",",Y,")").
>
> +fact(X,Y): X == 5<- .print("fact 5 == " ,Y).
>
>
> the output of the console is :
> [factornonrekursive] Updating beliefbase with: fact(4,24)
> [factornonrekursive] Updating beliefbase with: fact(3,6)
> [factornonrekursive] Updating beliefbase with: fact(2,2)
> [factornonrekursive] Updating beliefbase with: fact(1,1)
> [factornonrekursive] Updating beliefbase with: fact(0,1)
>
>
>
> Question 1: Is Agentspeak a rekursive language ? Because of the "false"=
> reverse order of the output?
> Question 2: Why does he print fact 5 == 120??  Look at the second plan!  
> if i modify the  firstplan to  +fact(X,Y): X *< *5 <- ... he prints !
>
> .
> When i modify the code to:
>
> fact(0,1).
>
> /* Initial goals */
>
>
> /* Plans */
>
> +fact(X,Y): X == 0<- .print("fact 0 == " ,Y).
> +fact(X,Y): X < 5 <- +fact (X+1, (X+1) *Y);.print("Updating beliefbase
> with: fact(",X,",",Y,")").
>
> he just print [factornonrekursive] fact 0 == 1
>
>
> Question 3 => so he didn`t do the second plan why ?? (The debugging
> method  showing  that the  beliefbase is  just  fact(0,1)
>
>
> I am a liitle bit confused !! Hopefully you can help me out!
>
>
> Best regards,
> MArtin
>
>  
>
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev 
> _______________________________________________
> Jason-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jason-users

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users