summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorGrzegorz Adam Hankiewicz <gradha@imap.cc>2013-04-14 22:52:21 +0200
committerGrzegorz Adam Hankiewicz <gradha@imap.cc>2013-04-15 20:55:38 +0200
commitbccf2a3ade2381e8c527e888f0ce9dd7fd6f42af (patch)
treef7c7f23331645a85e65475b35862069e4a63ef25
parent4f09794be9fb9b96728078712f01e990e0021929 (diff)
downloadNim-bccf2a3ade2381e8c527e888f0ce9dd7fd6f42af.tar.gz
Improves tutorial tuples example.
-rw-r--r--doc/tut1.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/tut1.txt b/doc/tut1.txt
index 746d11f01..7c2a35f94 100644
--- a/doc/tut1.txt
+++ b/doc/tut1.txt
@@ -1311,6 +1311,24 @@ integer.
   echo(person[0]) # "Peter"
   echo(person[1]) # 30
 
+  # You don't need to declare tuples in a separate type section.
+  var building: tuple[street: string, number: int]
+  building = ("Rue del Percebe", 13)
+  echo(building.street)
+  
+  # The following line does not compile, they are different tuples!
+  #person = building
+  # --> Error: type mismatch: got (tuple[street: string, number: int])
+  #     but expected 'TPerson'
+  
+  # The following works because the field names and types are the same.
+  var teacher: tuple[name: string, age: int] = ("Mark", 42)
+  person = teacher
+
+Even though you don't need to declare a type for a tuple to use it, tuples
+created with different field names will be considered different objects despite
+having the same field types.
+
 
 Reference and pointer types
 ---------------------------