------------------------------------
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.
--
Ian Tegebo
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
Except that the Inner function is defined before calling Outer, not during the
call of Outer.
It might help to realise that in Vim, 'function' is a command that defines a
function in global scope (or script scope sometimes). You can run this command
whenver you like to define a function, and it always does the same thing. It is
NOT a program syntactical construct that defines a function at the point where it
is placed in the code.
Ben.
Send instant messages to your online friends http://au.messenger.yahoo.com
"I'm exploring a functional programming style within vimL..."
Also, what do people call the language vim uses for extensions, e.g.
vimL(anguage), vim-script?
--
Ian Tegebo
Usually vimscript.