Factorial in POP-11

Example for versions Poplog 15.5 (POP-11)

This example uses recursive factorial definition. factorial(n) calculates the actual value of factorial, while loop(n) is used to loop through factorials of numbers between 0 and n, inclusive. >< is concatenation operator. Note that loop doesn’t return a value.

Alternatively, one could save function definitions to file fact.p, place it in Poplog working folder, and enter load fact.p in interactive mode to upload the contents of file.

define factorial(n);
    if n == 0 
        then 1
        else n * factorial(n - 1)
    endif
enddefine;

define loop(n);
    if n>0 
        then loop(n-1)
    endif;
    n >< '! = ' >< factorial(n) =>
enddefine;

loop(16) =>