Newsgroups: comp.lang.dylan
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsfeed.cit.cornell.edu!newsstand.cit.cornell.edu!news.kei.com!news.mathworks.com!newsfeed.internetmci.com!news.sprintlink.net!noc.netcom.net!netcom.com!netcom9.netcom.com!haahr
From: haahr@netcom.com (Paul Haahr)
Subject: Re: multiple return values
In-Reply-To: MC8531@mclink.it's message of 30 Oct 1995 08:19:35 -0500
To: MC8531@mclink.it (Enrico Colombini)
Message-ID: <HAAHR.95Oct30161409@netcom9.netcom.com>
Sender: haahr@netcom9.netcom.com
Organization: NETCOM On-line services
References: <9510301414.aa00163@ax433.mclink.it>
Date: Mon, 30 Oct 1995 16:14:09 GMT
Lines: 32

Enrico Colombini <MC8531@mclink.it> wrote:
> 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.

> 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.

> 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
