SRFI 31 Ashley Yakeley 05 Nov 2002 08:35 UTC

As an alternative to your 'rec', there's the fixed-point-finding function
'call-with-result' that I implemented in my Scheme interpreter HScheme.
call-with-result calls a function, passing to it the result that the
function will return. For instance:

  (define factorial (call-with-result (lambda (fact)
    (lambda (x)
      (if (equal? x 0) 1 (* x (fact (- x 1))))
    )
  )))

  (define stream1 (call-with-result (lambda (s)
    (cons 1 s)
  )))

It's a little time-travel trick. You can try it out here:
<http://hscheme.sourceforge.net/examples.html>

Unfortunately call-with-result seems to be incompatible with CPS (and
apparently therefore with call-with-current-continuation), so the
resulting Scheme isn't R5RS. HScheme comes in both flavours, but is not
yet R5RS-complete for other reasons.

--
Ashley Yakeley, Seattle WA