Skip to content

Instantly share code, notes, and snippets.

@tyru
Created March 20, 2010 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tyru/338769 to your computer and use it in GitHub Desktop.
Save tyru/338769 to your computer and use it in GitHub Desktop.
function! s:uniq(list) "{{{
let dict = {}
let counter = 1
for i in a:list
let dict[i] = counter
let counter += 1
endfor
function! s:cmp(a, b)
return a:a == a:b ? 0 : a:a > a:b ? 1 : -1
endfunction
function! s:_(a, b)
let [a, b] = [a:a, a:b]
return eval(s:expr)
endfunction
try
let s:expr = 's:cmp(dict[a], dict[b])'
return sort(keys(dict), 's:_')
finally
" コメントアウト有りだとE133: return not inside function
" コメントアウト無しだとE130: Unknown function s:cmp
"
" なんだかちゃんとfunctionとendfunctionの対応が理解できてないような...
"
delfunc s:cmp
delfunc s:_
unlet s:expr
endtry
endfunction "}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment