Home Explore Blog CI



neovim

3rd chunk of `runtime/doc/vimeval.txt`
3c104f3523c0b3e194c94629893fd5aa20e9bd67cd10decd0000000100000fa2
 ['foo'], myDict)
	call Cb('bar')

This will invoke the function as if using: >
	call myDict.Callback('foo', 'bar')

Note that binding a function to a Dictionary also happens when the function is
a member of the Dictionary: >

	let myDict.myFunction = MyFunction
	call myDict.myFunction()

Here MyFunction() will get myDict passed as "self".  This happens when the
"myFunction" member is accessed.  When assigning "myFunction" to otherDict
and calling it, it will be bound to otherDict: >

	let otherDict.myFunction = myDict.myFunction
	call otherDict.myFunction()

Now "self" will be "otherDict".  But when the dictionary was bound explicitly
this won't happen: >

	let myDict.myFunction = function(MyFunction, myDict)
	let otherDict.myFunction = myDict.myFunction
	call otherDict.myFunction()

Here "self" will be "myDict", because it was bound explicitly.


1.3 Lists ~
						*list* *List* *Lists* *E686*
A List is an ordered sequence of items.  An item can be of any type.  Items
can be accessed by their index number.  Items can be added and removed at any
position in the sequence.


List creation ~
							*E696* *E697*
A List is created with a comma-separated list of items in square brackets.
Examples: >
	:let mylist = [1, two, 3, "four"]
	:let emptylist = []

An item can be any expression.  Using a List for an item creates a
List of Lists: >
	:let nestlist = [[11, 12], [21, 22], [31, 32]]

An extra comma after the last item is ignored.


List index ~
							*list-index* *E684*
An item in the List can be accessed by putting the index in square brackets
after the List.  Indexes are zero-based, thus the first item has index zero. >
	:let item = mylist[0]		" get the first item: 1
	:let item = mylist[2]		" get the third item: 3

When the resulting item is a list this can be repeated: >
	:let item = nestlist[0][1]	" get the first list, second item: 12
<
A negative index is counted from the end.  Index -1 refers to the last item in
the List, -2 to the last but one item, etc. >
	:let last = mylist[-1]		" get the last item: "four"

To avoid an error for an invalid index use the |get()| function.  When an item
is not available it returns zero or the default value you specify: >
	:echo get(mylist, idx)
	:echo get(mylist, idx, "NONE")


List concatenation ~
							*list-concatenation*
Two lists can be concatenated with the "+" operator: >
	:let longlist = mylist + [5, 6]
	:let longlist = [5, 6] + mylist
To prepend or append an item, turn it into a list by putting [] around it.

A list can be concatenated with another one in-place using |:let+=| or
|extend()|: >
	:let mylist += [7, 8]
	:call extend(mylist, [7, 8])
<
See |list-modification| below for more about changing a list in-place.


Sublist ~
							*sublist*
A part of the List can be obtained by specifying the first and last index,
separated by a colon in square brackets: >
	:let shortlist = mylist[2:-1]	" get List [3, "four"]

Omitting the first index is similar to zero.  Omitting the last index is
similar to -1. >
	:let endlist = mylist[2:]	" from item 2 to the end: [3, "four"]
	:let shortlist = mylist[2:2]	" List with one item: [3]
	:let otherlist = mylist[:]	" make a copy of the List

Notice that the last index is inclusive.  If you prefer using an exclusive
index use the |slice()| method.

If the first index is beyond the last item of the List or the second item is
before the first item, the result is an empty list.  There is no error
message.

If the second index is equal to or greater than the length of the list the
length minus one is used: >
	:let mylist = [0, 1, 2, 3]
	:echo mylist[2:8]		" result: [2, 3]

NOTE: mylist[s:e] means using the variable "s:e" as index.  Watch out for
using a single letter variable before the ":".  Insert a space when needed:
mylist[s : e].


List identity ~
							*list-identity*
When variable "aa" is a list and you assign it to another variable "bb", both
variables refer to the same list.  Thus changing the list "aa" will also
change "bb": >
	:let aa = [1,

Title: Function References with Dictionaries and Arguments; Introduction to Lists
Summary
This section delves into function references (Funcrefs), specifically how they interact with dictionaries and arguments, explaining how binding a function to a dictionary impacts the 'self' argument during calls. It demonstrates partial function creation and invocation. Additionally, the segment introduces Lists, detailing their creation, indexing (including negative indexing), concatenation using '+' and extend(), and sublist extraction using slicing. It also covers List identity and how assigning one list variable to another results in both variables referencing the same underlying list.