diff options
author | Araq <rumpf_a@web.de> | 2013-03-16 09:46:28 -0700 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-03-16 09:46:28 -0700 |
commit | b75a335705afb798c684705d0c53784c0e4469f8 (patch) | |
tree | c792999f7242cfb60c35d5b3eb21d2b9d553b832 | |
parent | 5b7df8ed60ffc5c68c1485e7538e36c50142d0d0 (diff) | |
parent | 9cd4482aa1edebdb45a048177112c871466252ce (diff) | |
download | Nim-b75a335705afb798c684705d0c53784c0e4469f8.tar.gz |
Merge pull request #357 from gradha/pr_adds_newseq_documentation_example
Adds newSeq documentation example.
-rwxr-xr-x | lib/system.nim | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/system.nim b/lib/system.nim index 4aa7ecad5..8885de624 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -370,9 +370,34 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.} ## creates a new sequence of type ``seq[T]`` with length ``len``. ## This is equivalent to ``s = @[]; setlen(s, len)``, but more ## efficient since no reallocation is needed. + ## + ## Note that the sequence will be filled with uninitialized entries, which + ## can be a problem for sequences containing strings. After the creation of + ## the sequence you should assign entries to the sequence instead of adding + ## them. Example: + ## + ## .. code-block:: nimrod + ## var inputStrings : seq[string] + ## newSeq(inputStrings, 3) + ## inputStrings[0] = "The fourth" + ## inputStrings[1] = "assignment" + ## inputStrings[2] = "would crash" + ## #inputStrings[3] = "out of bounds" proc newSeq*[T](len = 0): seq[T] = ## creates a new sequence of type ``seq[T]`` with length ``len``. + ## + ## Note that the sequence will be filled with uninitialized entries, which + ## can be a problem for sequences containing strings. After the creation of + ## the sequence you should assign entries to the sequence instead of adding + ## them. Example: + ## + ## .. code-block:: nimrod + ## var inputStrings = newSeq[string](3) + ## inputStrings[0] = "The fourth" + ## inputStrings[1] = "assignment" + ## inputStrings[2] = "would crash" + ## #inputStrings[3] = "out of bounds" newSeq(result, len) proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {. |