Nicer English (#5513)
This commit is contained in:
parent
974b4d59b4
commit
ef59b1a8eb
1 changed files with 9 additions and 9 deletions
18
doc/tut1.rst
18
doc/tut1.rst
|
|
@ -1063,10 +1063,10 @@ Enumeration and object types may only be defined within a
|
||||||
|
|
||||||
Enumerations
|
Enumerations
|
||||||
------------
|
------------
|
||||||
A variable of an enumeration type can only be assigned a value of a
|
A variable of an enumeration type can only be assigned one of the enumeration's specified values.
|
||||||
limited set. This set consists of ordered symbols. Each symbol is mapped
|
These values are a set of ordered symbols. Each symbol is mapped
|
||||||
to an integer value internally. The first symbol is represented
|
to an integer value internally. The first symbol is represented
|
||||||
at runtime by 0, the second by 1 and so on. Example:
|
at runtime by 0, the second by 1 and so on. For example:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
|
|
@ -1077,17 +1077,17 @@ at runtime by 0, the second by 1 and so on. Example:
|
||||||
var x = south # `x` is of type `Direction`; its value is `south`
|
var x = south # `x` is of type `Direction`; its value is `south`
|
||||||
echo x # writes "south" to `stdout`
|
echo x # writes "south" to `stdout`
|
||||||
|
|
||||||
All comparison operators can be used with enumeration types.
|
All the comparison operators can be used with enumeration types.
|
||||||
|
|
||||||
An enumeration's symbol can be qualified to avoid ambiguities:
|
An enumeration's symbol can be qualified to avoid ambiguities:
|
||||||
``Direction.south``.
|
``Direction.south``.
|
||||||
|
|
||||||
The ``$`` operator can convert any enumeration value to its name, the ``ord``
|
The ``$`` operator can convert any enumeration value to its name, and the ``ord``
|
||||||
proc to its underlying integer value.
|
proc can convert it to its underlying integer value.
|
||||||
|
|
||||||
For better interfacing to other programming languages, the symbols of enum
|
For better interfacing to other programming languages, the symbols of enum
|
||||||
types can be assigned an explicit ordinal value. However, the ordinal values
|
types can be assigned an explicit ordinal value. However, the ordinal values
|
||||||
have to be in ascending order. A symbol whose ordinal value is not
|
must be in ascending order. A symbol whose ordinal value is not
|
||||||
explicitly given is assigned the value of the previous symbol + 1.
|
explicitly given is assigned the value of the previous symbol + 1.
|
||||||
|
|
||||||
An explicit ordered enum can have *holes*:
|
An explicit ordered enum can have *holes*:
|
||||||
|
|
@ -1142,8 +1142,8 @@ subrange types (and vice versa) are allowed.
|
||||||
|
|
||||||
The ``system`` module defines the important `Natural <system.html#Natural>`_
|
The ``system`` module defines the important `Natural <system.html#Natural>`_
|
||||||
type as ``range[0..high(int)]`` (`high <system.html#high>`_ returns the
|
type as ``range[0..high(int)]`` (`high <system.html#high>`_ returns the
|
||||||
maximal value). Other programming languages mandate the usage of unsigned
|
maximal value). Other programming languages may suggest the use of unsigned
|
||||||
integers for natural numbers. This is often **wrong**: you don't want unsigned
|
integers for natural numbers. This is often **unwise**: you don't want unsigned
|
||||||
arithmetic (which wraps around) just because the numbers cannot be negative.
|
arithmetic (which wraps around) just because the numbers cannot be negative.
|
||||||
Nim's ``Natural`` type helps to avoid this common programming error.
|
Nim's ``Natural`` type helps to avoid this common programming error.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue