Start documenting maps and work on some other docs a bit.

This commit is contained in:
Bob Nystrom
2015-01-25 11:08:13 -08:00
parent 492c730e6f
commit 3061bdde7f
7 changed files with 156 additions and 14 deletions
+21 -1
View File
@@ -1,4 +1,24 @@
^title Core Library
^category core
**TODO**
Because Wren is designed for [embedding in applications][embedding], its core
library is minimal and is focused on working with objects within Wren. For
stuff like file IO, graphics, etc., it is up to the host application to provide
interfaces for this.
All Wren source files automatically have access to the following classes:
* [Bool](bool.html)
* [Class](class.html)
* [Fiber](fiber.html)
* [Fn](fn.html)
* [List](list.html)
* [Map](map.html)
* [Null](null.html)
* [Num](num.html)
* [Object](object.html)
* [Range](range.html)
* [Sequence](sequence.html)
* [String](string.html)
[embedding]: ../embedding-api.html
+28 -4
View File
@@ -7,7 +7,7 @@ An indexable contiguous collection of elements. More details [here](../lists.htm
### **add**(item)
Appends `item` onto the end of the list.
Appends `item` to the end of the list.
### **clear**
@@ -28,12 +28,36 @@ for iterating over the elements in the list.
### **removeAt**(index)
**TODO**
Removes the element at `index`. If `index` is negative, it counts backwards
from the end of the list where `-1` is the last element. All trailing elements
are shifted up to fill in where the removed element was.
:::dart
var list = ["a", "b", "c", "d"]
list.removeAt(1)
IO.print(list) // "[a, c, d]".
It is a runtime error if the index is not an integer or is out of bounds.
### **[**index**]** operator
**TODO**
Gets the element at `index`. If `index` is negative, it counts backwards from
the end of the list where `-1` is the last element.
:::dart
var list = ["a", "b", "c"]
IO.print(list[1]) // "b".
It is a runtime error if the index is not an integer or is out of bounds.
### **[**index**]=**(item) operator
**TODO**
Replaces the element at `index` with `item`. If `index` is negative, it counts
backwards from the end of the list where `-1` is the last element.
:::dart
var list = ["a", "b", "c"]
list[1] = "new"
IO.print(list) // "[a, new, c]".
It is a runtime error if the index is not an integer or is out of bounds.
+53
View File
@@ -0,0 +1,53 @@
^title Map Class
^category core
An associative collection that maps keys to values. More details [here](../maps.html).
### **clear**
Removes all entries
### **count**
The number of entries in the map.
### **keys**
A [Sequence](sequence.html) that can be used to iterate over the keys in the
map. Note that iteration order is undefined. All keys will be iterated over,
but may be in any order, and may even change between invocations of Wren.
### **iterate**(iterator), **iteratorValue**(iterator)
Implements the [iterator protocol](../control-flow.html#the-iterator-protocol)
for iterating over the elements in the list.
### **removeAt**(key)
### **values**
A [Sequence](sequence.html) that can be used to iterate over the values in the
map. Note that iteration order is undefined. All values will be iterated over,
but may be in any order, and may even change between invocations of Wren.
If multiple keys are associated with the same value, the value will appear
multiple times in the sequence.
### **[**key**]** operator
Gets the value associated with `key` in the map. If `key` is not present in the
map, returns `null`.
:::dart
var map = {"george": "harrison", "ringo": "starr"}
IO.print(map["ringo"]) // "starr".
IO.print(map["pete"]) // "null".
### **[**key**]=**(value) operator
Associates `value` with `key` in the map. If `key` was already in the map, this
replaces the previous association.
It is a runtime error if the key is not a [Bool](bool.html),
[Class](class.html), [Null](null.html), [Num](num.html), [Range](range.html),
or [String](string.html).