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
ELSIF 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]
MODULE.CALL.ARGS
  Holds the list of arguments passed with MODULE.CALL.
  -> [arg1, ..., argN]

Procedures:

ACKERMANN.RETURN(result)
  End computation and show the calculated value.
  -> result: calculated integer value
MODULE.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 MODULE.CALL.ARGS
  Alternative syntax: retvar1, ..., retvarM := MODULE.CALL(@modname, arg1, ..., argN)
  Note that recursive module calls are not allowed.
MODULE.RETURN(retval1, ..., retvalM)
  Return M values from the current module.
  Resume execution at the next instruction of the corresponding MODULE.CALL.
  -> retval: value to be copied to the corresponding variable retvar

Additional examples can be found on GitHub.