cprint { sclass VStack implements Steppable { new L stack; O latestResult; void push(Computable computation) { stack.add(computation); } public bool step() { if (empty(stack)) false; last(stack).step(this, latestResult); true; } void _return(O value) { latestResult = value; removeLast(stack); } } asclass Computable { int currentStep; // 0 in the beginning abstract void step(VStack stack, O subComputationResult); } sclass f_ackermann extends Computable { BigInt a, b; *(BigInt *a, BigInt *b) {} void step(VStack stack, O subComputationResult) { if (currentStep == 0) { if (a.equals(BigInt.ZERO)) stack._return(plus(b, BigInt.ONE)); else if (b.equals(BigInt.ZERO)) { stack.push(new f_ackermann(a.subtract(BigInt.ONE), BigInt.ONE); currentStep = 1; } else { stack.push(new f_ackermann(a, minus(b, BigInt.ONE))); currentStep = 2; } } else if (currentStep == 1) stack._return(subComputationResult); else if (currentStep == 2) { stack.push(new f_ackermann(minus(a, BigInt.ONE), subComputationResult/BigInt)); currentStep = 1; } else fail(); } } start-thread { new VStack stack; stack.push(new f_ackermann(bigInt(2), bigInt(2))); stepAllWithStats(stack); print("Result: " + stack.latestResult); } }