Re: Newbie problem: naked left-hand reference
"Kjetil S. Matheussen" <[email protected]> Thu, 19 Apr 2007 21:30:52 +0200 (CEST)
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <Pine.LNX.4.64.0704192126240.8898@ttleush> |
On Thu, 19 Apr 2007, Jon Kleiser wrote:
> Thanks for explaining the "context for definition" thing! It helped me a
> lot. My first sisc program is now actually running, and it's quite fast.
> There is, however, one more error message that I've had that I don't quite
> understand. If I just remove a couple of expressions from my little sample
> program, so that it looks like this:
>
> (define desc-series
> (lambda (size)
> (let countdown ((n size) (s ()))
> (if (= n 0) s
> (countdown (- n 1) (append s (list n)))))))
>
> (define do-from-to
> (lambda (m n)
> (let loop ((i m))
> (begin
> (define i2 (* i i))
> (define ds (desc-series i2)) (display ds) (newline)
> (if (= i n) 'done
> (loop (+ i 1)))))))
>
> (do-from-to 2 4)
>
> Then, why do I get things like this:
>
> {warning: naked left-hand reference in letrec rhs: '%%_nNWd_9Tf51_i2'.}
(let loop ((i m))
(begin
(define i2 (* i i))
(define ds (desc-series i2))
...))
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 also have another question:
> What's the easiest way to meassure how long a part of a sisc program takes
> to execute?
>
The time function, perhaps... I use this macro:
(define-macro (c-time expr)
`(cadr (time (eval ',expr))))
(c-time (do-from-to 2 4))
-------------------------------------------------------------------------
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/