[Top][All Lists]

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

Re: [Chicken-users] Re: Style Guide

From: Sunnan
Subject: Re: [Chicken-users] Re: Style Guide
Date: Wed, 07 Nov 2007 12:39:54 +0100
User-agent: Thunderbird (X11/20071022)

Kon Lovett wrote:

(define (fib)
 (let loop ((a 1) (b 1))
   (set! fib (lambda () (loop b (+ a b))))

;; maybe non-portable outside of current chicken semantics?

Except for the caveat about some compilers, no. However the above doesn't "make" a generator, in the sense that it can be reused. To restart the sequence 'fib' must be rebound. Certainly not "disgusting", just of limited use.

I've used the idiom for more complex generators with multiple yield points but it quickly becomes tangled. I don't like the programming style that too many generators afford, so I don't do this so much. I usually use generator for generating ids where would use either a global variable or a state monad.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]