Prequel
primitive recursive driven programming


Factorial

(This example requires web workers.)

Enter an integer number between 0 and 7.

! = ...

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

Procedures:

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