[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Seemingly inconsistency between function in a local variable and local function
- From: Robert Klemme <shortcutter@...>
- Date: Tue, 3 Apr 2012 13:49:03 +0200
On Mon, Apr 2, 2012 at 10:08 PM, Sam Roberts <firstname.lastname@example.org> wrote:
> On Mon, Apr 2, 2012 at 7:38 AM, Robert Klemme
> <email@example.com> wrote:
>> On Mon, Apr 2, 2012 at 2:33 PM, Jerome Vuarand <firstname.lastname@example.org> wrote:
>>> 2012/4/2 Robert Klemme <email@example.com>:
>>>> Why is that? What did I overlook?
>>> Every time you write the keyword "local", you create/declare a new
>>> local variable, which can shadow another one with the same name.
>> Ah! I wasn't aware of that. Page http://www.lua.org/pil/4.2.html
>> does not mention this.
> The examples on that page show shadowing of local variable names.
But only with nesting, i.e. not the shadowing on the same level.
> Also: "The scope begins after the declaration and goes until the end
> of the block."
Hmm... But the statement is prefixed with "As such, you can write
local declarations anywhere you can write a statement." so it seems
the main point of the paragraph is the "anywhere" bit. And I cannot
find any mention that multiple local variables with the same
identifier inside a scope are legal in Lua - which is not too common
among programming languages. I agree, the fact can be deduced from
the page - but it could be worded much clearer.
remember.guy do |as, often| as.you_can - without end