From 622c73eeeb8943d058dac8a50bf4bb455648df0f Mon Sep 17 00:00:00 2001 From: Dov Murik Date: Fri, 12 Feb 2016 09:29:45 -0500 Subject: [PATCH] vimscript: add seq and string? Issue #166 --- vimscript/core.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/vimscript/core.vim b/vimscript/core.vim index f29fc47b..8925d14e 100644 --- a/vimscript/core.vim +++ b/vimscript/core.vim @@ -248,6 +248,10 @@ function MalSymbolQ(args) return BoolNew(SymbolQ(a:args[0])) endfunction +function MalStringQ(args) + return BoolNew(StringQ(a:args[0])) +endfunction + function MalKeyword(args) return KeywordNew(ObjValue(a:args[0])) endfunction @@ -280,6 +284,20 @@ function MalConj(args) endif endfunction +function MalSeq(args) + let obj = a:args[0] + if EmptyQ(obj) + return g:MalNil + elseif ListQ(obj) + return obj + elseif VectorQ(obj) + return ListNew(ObjValue(obj)) + elseif StringQ(obj) + return ListNew(map(split(ObjValue(obj), '\zs'), 'StringNew(v:val)')) + endif + throw "seq requires string or list or vector or nil" +endfunction + function MalMeta(args) return ObjMeta(a:args[0]) endfunction @@ -360,6 +378,7 @@ let CoreNs = { \ "false?": NewNativeFn("MalFalseQ"), \ "symbol": NewNativeFn("MalSymbol"), \ "symbol?": NewNativeFn("MalSymbolQ"), + \ "string?": NewNativeFn("MalStringQ"), \ "keyword": NewNativeFn("MalKeyword"), \ "keyword?": NewNativeFn("MalKeywordQ"), \ "list": NewNativeFn("MalList"), @@ -393,6 +412,7 @@ let CoreNs = { \ "map": NewNativeFn("MalMap"), \ "throw": NewNativeFn("MalThrow"), \ "conj": NewNativeFn("MalConj"), + \ "seq": NewNativeFn("MalSeq"), \ "meta": NewNativeFn("MalMeta"), \ "with-meta": NewNativeFn("MalWithMeta"), \ "atom": NewNativeFn("MalAtom"), -- 2.20.1