Continued fraction/Arithmetic/G(matrix ng, continued fraction n): Difference between revisions
Continued fraction/Arithmetic/G(matrix ng, continued fraction n) (view source)
Revision as of 14:19, 26 February 2023
, 1 year ago→{{header|Icon}}
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?
#
# generate = a co-expression to generate more terms.
record continued_fraction (terminated
procedure main ()
Line 4,404 ⟶ 4,406:
procedure make_continued_fraction (gen)
return continued_fraction (NO
end
Line 4,410 ⟶ 4,412:
local j, term
if *cf.
if \cf.terminated then {
fail
} else {
every j := *cf.
if term := @(cf.generate) then {
put (cf.memo, term)
} else {
cf.terminated := YES
|