Prequel
primitive recursive driven programming


Factorial

(This example requires web workers.)

Enter an integer number between 0 and 12.

! = ...

Run Pause Stop

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


Prequel program

Edit Save Debug

Module: FACTORIAL

 n := FACTORIAL.INPUT     
 result := 1              
 REPEAT n                 
  result *= n+1           
 ENDREP                   
 FACTORIAL.RETURN(result) 
	

Input:

FACTORIAL.INPUT
 The integer written in the editable text input.
 -> e.g. 5
MODULE.CALL.ARGS
 Holds the list of arguments passed with MODULE.CALL.
 -> [arg1, ..., argN]

Procedures:

FACTORIAL.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.