Fibonacci numbers in Algol68
Example for versions
Algol68g-1.18.0,
Algol68toc-1.8
Generative method. This code specimen uses a callback to generate the sequence on demand.
MODE YIELDINT = PROC(INT)VOID;
PROC fibonacci = (INT n, YIELDINT yield)VOID: (
INT even:=0, odd:=1;
yield(even);
yield(odd);
FOR i FROM odd+1 TO n DO
yield( (ODD i|odd|even) := odd + even )
OD
);
main:(
# FOR INT n IN # fibonacci(16, # ) DO ( #
## (INT n)VOID:(
print((" ",whole(n,0)))
)); # OD #
print(new line)
)
Comments
]]>blog comments powered by Disqus
]]>