musique/examples/factorial.mq
Robert Bendun ddf9cc8f8c New declaration syntax x := foo instead of var x = foo
Additionaly moving into multiparameter binary operations
2022-09-18 14:50:20 +02:00

16 lines
316 B
Plaintext

for := [ start stop iteration |
if (start > stop)
[nil]
[iteration start; for (start + 1) stop iteration]
];
factorial := [n | if (n <= 1) [1] [n * (factorial (n-1))]];
for 1 10 [i | say (factorial i)];
factorial_iterative := [n |
x := 1;
for 1 n [i|x *= i];
x
];
for 1 10 [i | say (factorial_iterative i)];