";;;; lisp.vim ";;;; Lisp inplementation by vim script ";;;; Author: Pocket <poketo7878@gmail.com> "Global variables"{{{ let s:nil = 'nil' "}}} "Type check functions"{{{ function! IsNumber(thing) if type(a:thing) == type(1) return 1 else return 0 endif endfunction function! IsString(thing) if type(a:thing) == type('test') return 1 else return 0 endif endfunction function! IsListp(thing) if type(a:thing) == type([]) return 1 else return 0 endif endfunction function! Atom(thing) return !IsListp(a:thing) endfunction function! Null(thing) if Atom(a:thing) if IsString(a:thing) if a:thing == 'nil' return 1 else return 0 endif else return 0 endif elseif IsListp(a:thing) && len(a:thing) == 0 return 1 else return 0 endif endfunction "}}} "Print functions"{{{ function! PrintList(list) echon '(' for i in range(0, len(a:list) - 1) if IsListp(a:list[i]) call PrintList(a:list[i]) else if !Null(a:list[i]) echon a:list[i] endif if i != (len(a:list) - 1) echon " " endif endif endfor echon ')' endfunction "}}} "List operations"{{{ function! Car(list) if Null(a:list) return s:nil elseif IsListp(a:list) return a:list[0] else return s:nil endif endfunction function! Cdr(list) if Null(a:list) return s:nil elseif IsListp(a:list) return a:list[1 :] else return s:nil endif endfunction "}}}
ちょっとしたリスト処理などを実装してみました。ちゃんと動作してるんですかね...?