diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2013-12-01 21:07:50 +0100 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2013-12-01 21:07:50 +0100 |
commit | d1284ff33d936ed9ab67db2cb85571d3c37e8feb (patch) | |
tree | 8575136781d8d988f92994e10fd867e7e5c7ea6b /doc | |
parent | 0a953de3a819de8d0a14943054427924f31ff05e (diff) | |
download | Nim-d1284ff33d936ed9ab67db2cb85571d3c37e8feb.tar.gz |
Mentions tuple unpacking only works in var/let blocks.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/tut1.txt | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/doc/tut1.txt b/doc/tut1.txt index b46fb2c68..2070c69d6 100644 --- a/doc/tut1.txt +++ b/doc/tut1.txt @@ -1361,13 +1361,13 @@ 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. -Tuples can be *unpacked* during variable assignment. This can be handy to -assign directly the fields of the tuples to individually named variables. An -example of this is the ``splitFile`` proc from the `os module <os.html>`_ which -returns the directory, name and extension of a path at the same time. For tuple -unpacking to work you have to use parenthesis around the values you want to -assign the unpacking to, otherwise you will be assigning the same value to all -the individual variables! Example: +Tuples can be *unpacked* during variable assignment (and only then!). This can +be handy to assign directly the fields of the tuples to individually named +variables. An example of this is the ``splitFile`` proc from the `os module +<os.html>`_ which returns the directory, name and extension of a path at the +same time. For tuple unpacking to work you have to use parenthesis around the +values you want to assign the unpacking to, otherwise you will be assigning the +same value to all the individual variables! Example: .. code-block:: nimrod @@ -1386,6 +1386,20 @@ the individual variables! Example: echo badname echo badext +Tuple unpacking **only** works in ``var`` or ``let`` blocks. The following code +won't compile: + +.. code-block:: nimrod + + import os + + var + path = "usr/local/nimrodc.html" + dir, name, ext = "" + + (dir, name, ext) = splitFile(path) + # --> Error: '(dir, name, ext)' cannot be assigned to + Reference and pointer types --------------------------- |