lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thankyou, all who answered this. Some of it went over my head, but there's nothing like a direct answer for making a newby study a subject a bit harder.


In answer to what I meant in my ill-thought request, I did mean first initialisation being equivalent to declaration.

The first use is often set to something anyway, so I'd hoped it might not ask much to have code that always expected this. 0 or "" or {} would do for most. If an 'if' statement had a first use that would not occur in one flow, being conditional, the compiler might be made to shout, prompting an earlier use of said var outside it, to be sure it won't break something by being absent. As far as I can see, it doesn't need to follow the procedure's many possibilites at runtime, but only to see that the first use it encounters is in a conditional branch. I've always avoided making new vars in such branches, as I've been taught that it's a bad habit. :) No actual teacher, I never had one.. but all the JavaScript, Basic, OPL (Psion thing) and anything else whose examples I studied, made a habit of avoiding such moves.

I'm not sure why making a variable outside a previous initalisation/declaration/assignment event (first use) would break the code, unless the name was the same. A compiler check for this might be hard, as it might not have any idea whether we mean it or not, but why not  leave it up to us. While we might not know the intricate mechanics of Lua, we could be trusted to drive it, surely. If we think about variable names, and don't re-use without reason, we'll be ok so long as we keep track of what we want in the program. (Which we have to do anyway..)

I'l admit to not knowing any extent of how difficult any variable behaviour change of this kind might be to make in the C code for lua, as I don't know C, and only know a little of JavaScript. I'm just looking from the perspective of someone who has been rightly enticed by Lua's offering of an immediate way to get things done, given some common sense, and a powerful and minimal syntax. If this idea does have worth, it might be worth applying before it becomes harder, as I guess it will, as Lua is further developed.