[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Make-rational-number-generator

This page is part of the web mail archives of SRFI 121 from before July 7th, 2015. The new archives for SRFI 121 contain all messages, not just those from before July 7th, 2015.



Here's something I found too late to put it into the first draft:

(make-rational-number-generator [ q ] )

Returns a generator of rational numbers starting with q (default 0)
according to the following recurrence:

    x' = (/ 1 (+ (* 2 (truncate x)) 1 (- x)))

It will generate all exact rationals once and only once in in the infinite
sequence 0, 1/2, 2, 1/3, 3/2, 3, 1/4, 4/3, 3/5, 5/2, 2/5, 3/4, 4, ...
It is an error if q is negative or inexact.

What do people think?

-- 
John Cowan          http://www.ccil.org/~cowan        cowan@xxxxxxxx
Fundamental thinking is ha-ard.  Let's go ideology-shopping.
                        --Philosopher Barbie