resource factorial
	import gl
	op fact(int index, int k , cap gl.answer ans ) {send}
body factorial()

   proc fact(index, k, ans)  {
	if (k<0) { send ans(index,-1)
	} else if (k==0 or k==1 ) { send ans(index,1)
	} else {
		# k is greater than 1 so compute k!
		op gl.answer myanswer
		int  kindex, kfact 
		send fact(index,k-1,myanswer)
		receive myanswer(kindex,kfact)
		send ans(index,k*kfact)
	}
   }

end
