Continued fraction/Arithmetic/G(matrix ng, continued fraction n): Difference between revisions

Line 4,290:
=={{header|Icon}}==
{{works with|Icon|9.5.22e}}
{{trans|ATS}}
 
This implementation memoizes terms of a continued fraction.
 
<syntaxhighlight lang="icon">
Line 4,298 ⟶ 4,301:
 
# terminated = are there no more terms to memoize?
# m memo = the number of memoized terms.
# memo = the terms.
# generate = a co-expression to generate more terms.
record continued_fraction (terminated, m, memo, generate)
 
procedure main ()
Line 4,404 ⟶ 4,406:
 
procedure make_continued_fraction (gen)
return continued_fraction (NO, 0, [], gen)
end
 
Line 4,410 ⟶ 4,412:
local j, term
 
if *cf.mmemo <= i then {
if \cf.terminated then {
fail
} else {
every j := *cf.mmemo to i do {
if term := @(cf.generate) then {
put (cf.memo, term)
cf.m +:= 1
} else {
cf.terminated := YES
1,448

edits