On Tue, 21 Sep 2010, Bee wrote:

why use "let str = a:str" in a function

Looking at some functions, I have seen "let str = a:str"

Why not just use a:str everywhere?
Other than typing convenience.

I'm presuming it's mainly typing convenience, but one reason that comes to mind is having a copy of the original value.

fun! Frobnicate(str)
        let str = a:str
        " lots of things that modify 'str'
        if str =~? "some horrible error"
                throw "Couldn't Frobnicate your string".
                \ string({'input': a:str,'partially frobnicated':str})
"...

Another might be 'mental' convenience... For a long time when I was learning Vimscript, I never remembered to type the 'a:'. 'let'ing to a function-local var of the same name would mitigate that problem.

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to