Prequel
primitive recursive driven programming


Listsort

(This example requires web workers.)

Sort these numbers in ascending order:

Shuffle: 10 73 45 32 98 25 17 33 88 61

Run Pause Stop

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


Prequel program

Edit Save Debug

Module: LISTSORT

 n = LISTSORT.INPUT.LENGTH                  
 REPEAT n                                    
  IF LISTSORT.INPUT[n-1] > LISTSORT.INPUT[n] 
   LISTSORT.MOVE(n-1, n)                   
  ENDIF                                     
 ENDREP                                      
	

Input:

LISTSORT.INPUT
 An unsorted list of numbers.
 -> e.g. [10, 73, 45, 32, 98, 25, 17, 33, 88, 61]
CALL.ARGS
 Holds the list of arguments passed with CALL.
 -> [arg1, ..., argN]

Procedures:

LISTSORT.MOVE(fromIndex, toIndex)
 Move list element at index fromIndex to index toIndex.
 -> fromIndex: integer between 0 and LISTSORT.INPUT.LENGTH-1
 -> toIndex: integer between 0 and LISTSORT.INPUT.LENGTH-1
 Restart program counter.
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.