diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-01-06 10:27:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 10:27:20 +0100 |
commit | dcb609efe45befba0271c9b89f2249fddd6e59be (patch) | |
tree | aabcc8a9c36cbbcfb6ed29727dad5ef865f59a51 | |
parent | 2c1d01086c35f88ab2e07fde52805e2023a54d44 (diff) | |
parent | 4b32b2cef64a408818442acd96b31ecd24a76dd2 (diff) | |
download | Nim-dcb609efe45befba0271c9b89f2249fddd6e59be.tar.gz |
Merge pull request #5175 from jlp765/patch-1
Tutorial1 additions
-rw-r--r-- | doc/tut1.rst | 30 |
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 ======= |