[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Multiple assignment (was Bug report: LUA compiler glitch)
- From: Dirk Laurie <dpl@...>
- Date: Wed, 10 Aug 2011 09:49:09 +0200
On Wed, Aug 10, 2011 at 02:14:37AM +0200, Steve Litt wrote:
> Can anyone explain the benefit of:
>
> a, b = 1, 2
It's occasionally useful to aid program readability, as in this
sort of situation:
r = sqrt(x^2+y^2)
c, s = x/r, y/r
where you are in effect working with vectors, but it is convenient
to have named rather than numerically indexed coordinates;
or this:
if x[i]>M then
j, M = i, x[i]
end
i.e. j and M are associated as closely and in the same way as i and
x[i].
But it does not aid readability to do e.g. this:
Churchill, answer_to_life_etc = "British statesman", 42
Dirk