summary refs log tree commit diff stats
path: root/doc/tut1.rst
diff options
context:
space:
mode:
authorjlp765 <jlp765@gmail.com>2017-01-03 12:06:34 +1000
committerGitHub <noreply@github.com>2017-01-03 12:06:34 +1000
commit4b32b2cef64a408818442acd96b31ecd24a76dd2 (patch)
treef9731e329cb5c959ce913a127afbdccfe462fa0c /doc/tut1.rst
parent5a1e0c25eb27b940abc604e1c3ed965477c89c1b (diff)
downloadNim-4b32b2cef64a408818442acd96b31ecd24a76dd2.tar.gz
Tutorial1 additions
Add extra For Statement stuff
Add Distinct Types
Diffstat (limited to 'doc/tut1.rst')
-rw-r--r--doc/tut1.rst30
1 files changed, 29 insertions, 1 deletions
diff --git a/doc/tut1.rst b/doc/tut1.rst
index d896a7044..32faf6168 100644
--- a/doc/tut1.rst
+++ b/doc/tut1.rst
@@ -380,6 +380,28 @@ Since counting up occurs so often in programs, Nim also has a `..
   for i in 1..10:
     ...
 
+Zero-indexed counting have two shortcuts ``..<`` and ``..^`` to simplify counting to one less then the higher index:
+
+.. code-block:: nim
+  for i in 0..<10:
+    ...  # 0..9
+
+or
+
+.. code-block:: nim
+  var s = "some string"
+  for i in 0..<s.len:
+    ...
+
+Other useful iterators for collections (like arrays and sequences) are
+* ``items`` and ``mitems``, which provides immutable and mutable elements respectively, and 
+* ``pairs`` and ``mpairs`` which provides the element and an index number (immutable and mutable respectively)
+
+.. code-block:: nim
+  for indx, itm in ["a","b"].pairs:
+    echo itm, " at index ", indx
+  # => a at index 0
+  # => b at index 1
 
 Scopes and the block statement
 ------------------------------
@@ -1516,8 +1538,14 @@ Example:
 A subtle issue with procedural types is that the calling convention of the
 procedure influences the type compatibility: procedural types are only compatible
 if they have the same calling convention. The different calling conventions are
-listed in the `manual <manual.html>`_.
+listed in the `manual <manual.html#types-procedural-type>`_.
 
+Distinct type
+-------------
+A Distinct type allows for the creation of new type that "does not imply a subtype relationship  between it and its base type".
+You must EXPLICITLY define all behaviour for the distinct type.
+To help with this, both the distinct type and its base type can cast from one type to the other.
+Examples are provided in the `manual <manual.html#types-distinct-type>`_.
 
 Modules
 =======