Ian Tegebo wrote:
> I'm exploring functional programming with vimL and immediately ran into
> seemingly counter-intuitive behavior:
>
> ------------------------------------
> function! Outer()
> let outer_var = 0
> function! Inner()
> let outer_var += 1
> endfunction
> call Inner()
> echo outer_var
> endfunction
>
> call Outer()
> -------------------------------------
>
> The result, when I run this from 7.1.156, is that 'Inner' reports
> 'outer_var' as
> unknown. I was expecting '0' but would eventually like to have my 'Inner'
> use 'outer_var' as state via dictionaries or some other mechanism. It's
> disturbing that 'outer_var' is not available to 'Inner'.
>
> Am I missing something? Is this the intended behavior? If so, where else
> can I read more about scoping? I've been reading usr_41.txt and eval.txt.
>
Inside a function, a variable name without a scope is the same as l: -- i.e.,
local to the _current_ function. Now there is no outer_var defined _inside_
the Inner() function, so it properly gives an error.
Variables local to Outer() are not accessinle to Inner(). From both of them
you can access most variables except function arguments and function-local
variables.
See ":help internal-variables" (and what it resends to) for details.
Best regards,
Tony.
--
If you cannot convince them, confuse them.
-- Harry S Truman
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---