Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Created July 31, 2016 19:19
Show Gist options
  • Save osyo-manga/ad08d62c37fc078cdac85e697a23dc17 to your computer and use it in GitHub Desktop.
Save osyo-manga/ad08d62c37fc078cdac85e697a23dc17 to your computer and use it in GitHub Desktop.
function! s:init(value)
let value = a:value
" 初期値に基づいて関数を定義する
function! s:hoge() closure
return value + value
endfunction
function! s:bar(value) closure
return value + a:value
endfunction
endfunction
" 任意の値で初期化して関数を定義する
call s:init(42)
echo s:hoge()
" => 84
echo s:bar(-20)
" => 22
" 任意の値で関数を書き換える
call s:init(-4)
echo s:hoge()
" => -8
echo s:bar(-20)
" => -24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment