diff --git a/content/seqs.md b/content/seqs.md index e69de29..f1ee50f 100644 --- a/content/seqs.md +++ b/content/seqs.md @@ -0,0 +1,33 @@ +--- +title: Seqs +--- + +# Seqs + +Seqs provide dynamically expandable storage, they are extended as needed. There are two ways to create seqs, with the `@` operator and with the `newSeq[T](n: int)` method. + +Seqs have value semantics, so + +``` nimrod +let a = @[1, 2, 3] +a[1] = 5 +``` + +will fail to compile because `a` cannot be assigned to. However, + +``` nimrod +var b = @[1, 2, 3] +b[1] = 5 +``` + +will work without any problems. If wanted, a seq can be passed to a method with the `var` annotation to make it modifiable, so + +``` nimrod +proc foo(mySeq: var seq[int]) = + mySeq[0] = 999 + +var thisSeq = @[1, 2, 3, 4] +foo(thisSeq) + +assert thisSeq[0] == 999 +``` \ No newline at end of file diff --git a/content/toc.md b/content/toc.md index f6713d8..9731d06 100644 --- a/content/toc.md +++ b/content/toc.md @@ -16,7 +16,7 @@ * [Distinct Types](/types/distinct/) * [Strings](/strings/) * [Arrays](/arrays/) -* [Sequences](/seqs/) +* [Seqs](/seqs/) * [Bitsets](/bitsets/) * [Procedures](/procs/) * [Exceptions](/exceptions/)