-*eval.txt* For Vim version 8.1. Last change: 2019 Jan 17
+*eval.txt* For Vim version 8.1. Last change: 2019 Jan 21
VIM REFERENCE MANUAL by Bram Moolenaar
1. Variables *variables*
1.1 Variable types ~
- *E712*
+ *E712* *E896* *E897* *E898*
There are nine types of variables:
Number A 32 or 64 bit signed number. |expr-number| *Number*
A Blob can be created with a |blob-literal|: >
:let b = 0zFF00ED015DAF
+Dots can be inserted between bytes (pair of hex characters) for readability,
+they don't change the value: >
+ :let b = 0zFF00.ED01.5DAF
A blob can be read from a file with |readfile()| passing the {type} argument
set to "B", for example: >
*eval()*
eval({string}) Evaluate {string} and return the result. Especially useful to
turn the result of |string()| back into the original value.
- This works for Numbers, Floats, Strings and composites of
- them. Also works for |Funcref|s that refer to existing
+ This works for Numbers, Floats, Strings, Blobs and composites
+ of them. Also works for |Funcref|s that refer to existing
functions.
eventhandler() *eventhandler()*
Return a |List| with all the key-value pairs of {dict}. Each
|List| item is a list with two items: the key of a {dict}
entry and the value of this entry. The |List| is in arbitrary
- order.
+ order. Also see |keys()| and |values()|.
+ Example: >
+ for [key, value] in items(mydict)
+ echo key . ': ' . value
+ endfor
job_getchannel({job}) *job_getchannel()*
Get the channel handle that {job} is using.
- A trailing comma in an array and object is ignored, e.g.
"[1, 2, ]" is the same as "[1, 2]".
- Integer keys are accepted in objects, e.g. {1:2} is the
- same as {'1':2}.
+ same as {"1":2}.
- More floating point numbers are recognized, e.g. "1." for
"1.0", or "001.2" for "1.2". Special floating point values
"Infinity", "-Infinity" and "NaN" (capitalization ignored)
- Control characters U+0000 through U+001F which are not
escaped in strings are accepted, e.g. " " (tab
character in string) for "\t".
+ - An empty JSON expression or made of only spaces is accepted
+ and results in v:none.
- Backslash in an invalid 2-character sequence escape is
ignored, e.g. "\a" is decoded as "a".
- A correct surrogate pair in JSON strings should normally be
keys({dict}) *keys()*
Return a |List| with all the keys of {dict}. The |List| is in
- arbitrary order.
+ arbitrary order. Also see |items()| and |values()|.
*len()* *E701*
len({expr}) The result is a Number, which is the length of the argument.
*string()*
string({expr}) Return {expr} converted to a String. If {expr} is a Number,
- Float, String or a composition of them, then the result can be
- parsed back with |eval()|.
+ Float, String, Blob or a composition of them, then the result
+ can be parsed back with |eval()|.
{expr} type result ~
String 'string' (single quotes are doubled)
Number 123
Float 123.123456 or 1.123456e8
Funcref function('name')
+ Blob 0z00112233.44556677.8899
List [item, item]
Dictionary {key: value, key: value}
values({dict}) *values()*
Return a |List| with all the values of {dict}. The |List| is
- in arbitrary order.
+ in arbitrary order. Also see |items()| and |keys()|.
virtcol({expr}) *virtcol()*
#endif
static char *e_listarg = N_("E686: Argument of %s must be a List");
+static char *e_listblobarg = N_("E898: Argument of %s must be a List or Blob");
static char *e_stringreq = N_("E928: String required");
#ifdef FEAT_FLOAT
}
}
else
- emsg(_(e_listreq));
+ emsg(_(e_listblobreq));
}
/*
}
}
else
- semsg(_(e_listdictarg), "get()");
+ semsg(_(e_listdictblobarg), "get()");
if (tv == NULL)
{
}
else if (argvars[0].v_type != VAR_LIST)
{
- emsg(_(e_listreq));
+ emsg(_(e_listblobreq));
return;
}
copy_tv(&argvars[0], rettv);
}
else if (argvars[0].v_type != VAR_LIST)
- semsg(_(e_listarg), "insert()");
+ semsg(_(e_listblobarg), "insert()");
else if ((l = argvars[0].vval.v_list) != NULL && !tv_check_lock(l->lv_lock,
(char_u *)N_("insert() argument"), TRUE))
{
}
}
else if (argvars[0].v_type != VAR_LIST)
- semsg(_(e_listdictarg), "remove()");
+ semsg(_(e_listdictblobarg), "remove()");
else if ((l = argvars[0].vval.v_list) != NULL
&& !tv_check_lock(l->lv_lock, arg_errmsg, TRUE))
{
}
if (argvars[0].v_type != VAR_LIST)
- semsg(_(e_listarg), "reverse()");
+ semsg(_(e_listblobarg), "reverse()");
else if ((l = argvars[0].vval.v_list) != NULL
&& !tv_check_lock(l->lv_lock,
(char_u *)N_("reverse() argument"), TRUE))
EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s"));
EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s"));
EXTERN char e_listreq[] INIT(= N_("E714: List required"));
+EXTERN char e_listblobreq[] INIT(= N_("E897: List or Blob required"));
EXTERN char e_listdictarg[] INIT(= N_("E712: Argument of %s must be a List or Dictionary"));
+EXTERN char e_listdictblobarg[] INIT(= N_("E896: Argument of %s must be a List, Dictionary or Blob"));
#endif
#ifdef FEAT_QUICKFIX
EXTERN char e_readerrf[] INIT(= N_("E47: Error while reading errorfile"));
call assert_fails('let b = 0z1.1')
call assert_fails('let b = 0z.')
call assert_fails('let b = 0z001122.')
+ call assert_fails('call get("", 1)', 'E896:')
endfunc
" assignment to a blob
call assert_equal(0z00112233, b)
call assert_fails('call add(b, [9])', 'E745:')
+ call assert_fails('call add("", 0x01)', 'E897:')
endfunc
func Test_blob_empty()
call assert_fails("call remove(b, 5)", 'E979:')
call assert_fails("call remove(b, 1, 5)", 'E979:')
call assert_fails("call remove(b, 3, 2)", 'E979:')
- call assert_fails("call remove(1, 0)", 'E712:')
+ call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(b, b)", 'E974:')
endfunc
call assert_equal(2, index(0z11111111, 0x11, -2))
call assert_equal(3, index(0z11110111, 0x11, -2))
- call assert_fails('call index("asdf", 0)', 'E714:')
+ call assert_fails('call index("asdf", 0)', 'E897:')
endfunc
func Test_blob_insert()
call assert_fails("call remove(l, 5)", 'E684:')
call assert_fails("call remove(l, 1, 5)", 'E684:')
call assert_fails("call remove(l, 3, 2)", 'E16:')
- call assert_fails("call remove(1, 0)", 'E712:')
+ call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(l, l)", 'E745:')
endfunc
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 1))
call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 'i'))
call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
+
+ call assert_fails('call reverse("")', 'E898:')
endfunc
" splitting a string to a List
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 793,
/**/
792,
/**/