From 201bd63e94cc3e1704d8e7ce6a00eb9e6e1eb4f1 Mon Sep 17 00:00:00 2001 From: flaviut Date: Sun, 13 Jul 2014 19:38:16 -0400 Subject: [PATCH] Initial revision of seqs --- content/seqs.md | 33 +++++++++++++++++++++++++++++++++ content/toc.md | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) 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/)