Poplog 15.5 (POP-11)
Version of implementation Poplog (POP-11) of programming language POP-11A version of Poplog.
Examples:
Hello, World! - POP-11 (75):
=>
is output operator.
'Hello, World!' =>
Factorial - POP-11 (76):
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) =>
Fibonacci numbers - POP-11 (77):
This example uses recursive definition of Fibonacci numbers and works in the same way as factorial example, except for that loop
returns a string which contains a concatenation of all Fibonacci numbers up to n-th.
define fibonacci(n);
if n < 3
then 1
else fibonacci(n - 1) + fibonacci(n - 2)
endif
enddefine;
define loop(n);
if n>1
then loop(n-1) >< ', ' >< fibonacci(n)
else fibonacci(n)
endif;
enddefine;
loop(16) >< ', ...' =>
Comments
]]>blog comments powered by Disqus
]]>