summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2015-07-14 09:05:44 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2015-07-14 09:05:44 +0100
commit6c8e9da9ee8173091931980b64aa21a839fc1424 (patch)
tree281d6529803502a3bf7a1c90892478b0081e1614
parentf7bdc205c7d3da8d80e9dec11e6d648ab433af5f (diff)
parentc05b3299fb03ceeb7405428f20d9d0885e2cf15a (diff)
downloadNim-6c8e9da9ee8173091931980b64aa21a839fc1424.tar.gz
Merge pull request #3111 from rafaelx/patch-2
Update tut1.txt
-rw-r--r--doc/tut1.txt21
1 files changed, 19 insertions, 2 deletions
diff --git a/doc/tut1.txt b/doc/tut1.txt
index 23d8a9b57..0d2de3c1e 100644
--- a/doc/tut1.txt
+++ b/doc/tut1.txt
@@ -1234,8 +1234,8 @@ Example:
 .. code-block:: nim
 
   var
-    x: seq[int] # a sequence of integers
-  x = @[1, 2, 3, 4, 5, 6] # the @ turns the array into a sequence
+    x: seq[int] # a reference to a sequence of integers
+  x = @[1, 2, 3, 4, 5, 6] # the @ turns the array into a sequence allocated on the heap
 
 Sequence variables are initialized with ``nil``. However, most sequence
 operations cannot deal with ``nil`` (leading to an exception being
@@ -1279,6 +1279,23 @@ The `len <system.html#len,TOpenArray>`_, `low <system.html#low>`_ and `high
 with a compatible base type can be passed to an openarray parameter, the index
 type does not matter.
 
+.. code-block:: nim
+  var 
+    fruits:   seq[string]       # reference to a sequence of strings that is initialized with 'nil'
+    capitals: array[3, string]  # array of strings with a fixed size
+  
+  fruits = @[]                  # creates an empty sequence on the heap that will be referenced by 'fruits'
+  
+  capitals = ["New York", "London", "Berlin"]   # array 'capitals' allows only assignment of three elements
+  fruits.add("Banana")          # sequence 'fruits' is dynamically expandable during runtime
+  fruits.add("Mango")
+  
+  proc openArraySize(oa: openArray[string]): int =
+    oa.len
+  
+  assert openArraySize(fruits) == 2     # procedure accepts a sequence as parameter
+  assert openArraySize(capitals) == 3   # but also an array type
+
 The openarray type cannot be nested: multidimensional openarrays are not
 supported because this is seldom needed and cannot be done efficiently.