Re: Newbie problem: naked left-hand reference
"Kjetil S. Matheussen" <[email protected]> Thu, 19 Apr 2007 21:47:43 +0200 (CEST)
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <Pine.LNX.4.64.0704192145241.8898@ttleush> |
On Thu, 19 Apr 2007, Victor Rodriguez wrote: > On 4/19/07, Kjetil S. Matheussen <[email protected]> wrote: >> On Thu, 19 Apr 2007, Jon Kleiser wrote: >> > ... >> is another way of writing >> >> (let loop ((i m)) >> (letrec ((i2 (* i i)) >> (ds (desc-series i2))) >> ...)) >> >> which gives undefined behaviour because you shouldn't reference already >> defined variables in variables in a letrec block. (Hmm, that was probably >> a bad explanation). Anyway, the reference to "i2" is the problem, since >> its defined elsewhere in the letrec. > > I do not really understand the explanation. > >From r5rs 4.2.2: "One restriction on letrec is very important: it must be possible to evaluate each hiniti without assigning or referring to the value of any hvariablei. If this restriction is violated, then it is an error." > Here is a way to solve the problem (and better style, IMO): > > (define do-from-to > (lambda (m n) > (let loop ((i m)) > (let* ((i2 (* i i)) > (ds (desc-series i2))) > (display ds) > (newline) > (if (= i n) 'done > (loop (+ i 1))))))) > > Best Regards, > No, I don't agree thats better style. In my opinion, the original code should have been valid. It will probably be valid in r6rs though. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/