diff options
author | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2017-07-24 21:50:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 21:50:09 +0000 |
commit | 8dd1d6d6461ff0ed7097d05f5abf2d94b2278a9b (patch) | |
tree | 234845f0347e94c4eff9c2b74f83636d85545f7c | |
parent | f169f5f55b124a586d92d51fdec0145e41fb4d1f (diff) | |
download | meson-8dd1d6d6461ff0ed7097d05f5abf2d94b2278a9b.zip meson-8dd1d6d6461ff0ed7097d05f5abf2d94b2278a9b.tar.gz meson-8dd1d6d6461ff0ed7097d05f5abf2d94b2278a9b.tar.bz2 |
Clarify array immutability and document indexing
-rw-r--r-- | docs/markdown/Syntax.md | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/docs/markdown/Syntax.md b/docs/markdown/Syntax.md index 09369e6..cf8ead2 100644 --- a/docs/markdown/Syntax.md +++ b/docs/markdown/Syntax.md @@ -194,19 +194,37 @@ Arrays are delimited by brackets. An array can contain an arbitrary number of ob my_array = [1, 2, 'string', some_obj] ``` -You can add additional items to an array like this: +Accessing elements of an array can be done via array indexing: ```meson -my_array += [ 'foo', 3, 4, another_obj ] +my_array = [1, 2, 'string', some_obj] +second_element = my_array[1] +last_element = my_array[-1] +``` + +You can add more items to an array like this: + +```meson +my_array += ['foo', 3, 4, another_obj] ``` +When adding a single item, you do not need to enclose it in an array: + +```meson +my_array += ['something'] +# This also works +my_array += 'else' +``` + +Note that this will create a new `my_array` object instead of appending to the old one since all objects in Meson are immutable. + #### Array methods The following methods are defined for all arrays: - `length`, the size of the array - `contains`, returns `true` if the array contains the object given as argument, `false` otherwise - - `get`, returns the object at the given index, negative indices count from the back of the array, indexing out of bounds is a fatal error + - `get`, returns the object at the given index, negative indices count from the back of the array, indexing out of bounds is a fatal error. Provided for backwards-compatibility, it is identical to array indexing. Function calls -- |