1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 02:45:44 +03:00

vimscript: Use map and lambda in EvalAst

This commit is contained in:
Dov Murik 2016-10-26 08:19:38 +00:00
parent b628a22074
commit 4fbbe5719c
10 changed files with 18 additions and 91 deletions

View File

@ -15,7 +15,6 @@ function NewEnvWithBinds(outer, binds, exprs)
while i < ListCount(a:binds)
let varname = ListNth(a:binds, i).val
if varname == "&"
" TODO
let restvarname = ListNth(a:binds, i + 1).val
let restvarvalues = ListDrop(a:exprs, i)
call env.set(restvarname, restvarvalues)

View File

@ -15,17 +15,9 @@ function EvalAst(ast, env)
end
return a:env[varname]
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -13,17 +13,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -14,17 +14,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -14,17 +14,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -14,17 +14,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -32,17 +32,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -57,17 +57,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -59,17 +59,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)

View File

@ -59,17 +59,9 @@ function EvalAst(ast, env)
let varname = a:ast.val
return a:env.get(varname)
elseif ListQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return ListNew(ret)
return ListNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif VectorQ(a:ast)
let ret = []
for e in a:ast.val
call add(ret, EVAL(e, a:env))
endfor
return VectorNew(ret)
return VectorNew(map(copy(a:ast.val), {_, e -> EVAL(e, a:env)}))
elseif HashQ(a:ast)
let ret = {}
for [k,v] in items(a:ast.val)