Tweak some docs.
This commit is contained in:
@@ -20,20 +20,20 @@ element you want. Like most languages, indexes start at zero:
|
||||
|
||||
:::wren
|
||||
var hirsute = ["sideburns", "porkchops", "'stache", "goatee"]
|
||||
hirsute[0] //> sideburns
|
||||
hirsute[1] //> porkchops
|
||||
System.print(hirsute[0]) //> sideburns
|
||||
System.print(hirsute[1]) //> porkchops
|
||||
|
||||
Negative indices counts backwards from the end:
|
||||
|
||||
:::wren
|
||||
hirsute[-1] //> goatee
|
||||
hirsute[-2] //> 'stache
|
||||
System.print(hirsute[-1]) //> goatee
|
||||
System.print(hirsute[-2]) //> 'stache
|
||||
|
||||
It's a runtime error to pass an index outside of the bounds of the list. If you
|
||||
don't know what those bounds are, you can find out using count:
|
||||
|
||||
:::wren
|
||||
hirsute.count //> 4
|
||||
System.print(hirsute.count) //> 4
|
||||
|
||||
## Slices and ranges
|
||||
|
||||
@@ -41,7 +41,7 @@ Sometimes you want to copy a chunk of elements from a list. You can do that by
|
||||
passing a [range](values.html#ranges) to the subscript operator, like so:
|
||||
|
||||
:::wren
|
||||
hirsute[1..2] //> [porkchops, 'stache]
|
||||
System.print(hirsute[1..2]) //> [porkchops, 'stache]
|
||||
|
||||
This returns a new list containing the elements of the original list whose
|
||||
indices are within the given range. Both inclusive and exclusive ranges work
|
||||
@@ -85,9 +85,9 @@ back. Doing so counts back from the size of the list *after* it's grown by one:
|
||||
:::wren
|
||||
var letters = ["a", "b", "c"]
|
||||
letters.insert(3, "d") // OK: inserts at end.
|
||||
System.print(letters) //> [a, b, c, d]
|
||||
System.print(letters) //> [a, b, c, d]
|
||||
letters.insert(-2, "e") // Counts back from size after insert.
|
||||
System.print(letters) //> [a, b, c, e, d]
|
||||
System.print(letters) //> [a, b, c, e, d]
|
||||
|
||||
## Removing elements
|
||||
|
||||
|
||||
Reference in New Issue
Block a user