Prequel
primitive recursive driven programming


Ackermann

(This example requires web workers.)

Enter two non-negative integer numbers.
(Note that the Ackermann function grows very rapidly, even for small inputs.)

A(, ) = ...

Run Pause Stop

0
0
0
← calls
← instructions
← memory (max use: 0)


Prequel program

Edit Save Debug

Module: ACKERMANN

IF ackermann IS UNDEFINED
ackermann = [ACKERMANN.INPUT]
ENDIF
m_n = ackermann.POP
IF m_n[0] == 0
IF ackermann.LENGTH == 0
ACKERMANN.RETURN(m_n[1]+1)
ENDIF
prev_m_n = ackermann.POP
prev_m_n.PUSH m_n[1]+1
ackermann.PUSH prev_m_n
ELIF m_n[1] == 0
m_n[0] -= 1
m_n[1] = 1
ackermann.PUSH m_n
ELSE
ackermann.PUSH [m_n[0]-1]
m_n[1] -= 1
ackermann.PUSH m_n
ENDIF

Input:

ACKERMANN.INPUT
 The list of values written in the editable text input.
 -> e.g. [3, 2]
CALL.ARGS
 Holds the list of arguments passed with CALL.
 -> [arg1, ..., argN]

Procedures:

ACKERMANN.RETURN(result)
 End computation and show the calculated value.
 -> result: calculated integer value
CALL(&retvar1, ..., &retvarM, @modname, arg1, ..., argN)
 Start executing module modname, copying N arguments and expecting M return values.
 -> retvar: name of variable to hold the corresponding return value retval
 -> modname: name of module to start executing
 -> arg: value to be copied to the list CALL.ARGS
 Alternative syntax: retvar1, ..., retvarM = CALL(@modname, arg1, ..., argN)
 Note that recursive module calls are not allowed.
RETURN(retval1, ..., retvalM)
 Return M values from the current module.
 Resume execution at the next instruction of the corresponding CALL.
 -> retval: value to be copied to the corresponding variable retvar

Additional examples can be found on GitHub.