[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: local-ity of undef parameter
- From: spir <denis.spir@...>
- Date: Tue, 8 Dec 2009 19:57:22 +0100
David Given <email@example.com> dixit:
> spir wrote:
> > output = function(thing, level)
> > Is here 'level' local in the case it was not defined inthe calling expression?
> Parameters are always local; if a value isn't specified when your
> function was called, then it'll be initialised to nil. It's the
> *declaration in the function* that matters, not how your function was
Thank you very much, this is exactly what I was wondering.
(Actually, I find there is a bit of ambiguity around the sense of 'nil', or maybe I haven't it right yet. I would like a value that means *only* 'undef' or 'unkown in reachable scope', in a way acting like #ifdef, but that we cannot even assign to a name.)
> > if not level then local level = 1
> In fact, this won't do what you expect. 'local' defines variables in the
> enclosing scope --- which here is the then...end block.
Right, I was caught! See how bad it is to write a conditionned block without newline/indent... I did not even realise there is a scope in there.
> local var = 1
> if true then
> local var = 2
> print(var) -- outputs 2!
> print(var) -- outputs 1!
Thank you again.
la vita e estrany