Posted to tcl by kbk at Tue Aug 17 22:37:31 GMT 2010view raw

  1. proc cfhomo {a b c d x} {
  2. while {1} {
  3.  
  4. # Egest what terms we can
  5.  
  6. while {1} {
  7. set prod [* $c $d]
  8. if {$prod == Inf || $prod <= 0} break
  9. set qcoef [/ $a $c]
  10. set rcoef [% $a $c]
  11. set qconst [/ $b $d]
  12. set rconst [% $b $d]
  13. if {$qconst != $qcoef} break
  14. Yield $qconst [list $x 1]
  15. lassign [list $c $d $rcoef $rconst] a b c d
  16. }
  17.  
  18. # Ingest the next term of the input
  19.  
  20. set t [$x]
  21. if {$t == Inf} {
  22. tailcall cfint/int $a $c
  23. }
  24. lassign [list [expr {$t*$a + $b}] $a [expr {$t*$c + $d}] $c] a b c d
  25. }
  26. }