/ test / contracts / factorial.aes
factorial.aes
 1  // An implementation of the factorial entrypoint where each recursive
 2  // call is to another contract. Not the cheapest way to compute factorial.
 3  contract interface FactorialServer =
 4    entrypoint fac : (int) => int
 5  
 6  contract Factorial =
 7  
 8    record state = {worker : FactorialServer}
 9  
10    entrypoint init(worker) = {worker = worker}
11  
12    stateful entrypoint set_worker(worker) = put(state{worker = worker})
13  
14    entrypoint fac(x : int) : int =
15      if(x == 0) 1
16      else x * state.worker.fac(x - 1)
17