Quote:
> Is there a penalty for binding new variables with the same
> name at every iteration of a looping construct?
In typical implementations, I expect not.
Quote:
> For example:
> for (m in months)
> let work-days = ... ;
> end for;
> vs:
> let work-days = 0;
> for (m in months)
> work-days := ... ;
> end for;
> A C programmer would avoid the former, thinking that a new local
> variable would be created (possibly from the stack) at every
> iteration.
I hope a typical C programmer wouldn't think that. For most C
compilers, thinking such a thing would be incorrect.
Quote:
> I suspect that that is not the case in Dylan, but never read it
> explicitly anywhere... and I know very little of Lisp.
I don't think you can say always, but I'd be very surprised if any Dylan
implementation makes the second version less expensive than the first,
given the difficulties of optimizing assignment. Good compilers will
notice that the initialization with 0 isn't used and omit that piece of
code, and then generate identical instructions for those loops.
Paul