docs: say that nil can be used as a value (#13756)
and improve wording in other ways Showing that `nil` can be assigned helps to warn readers that variables can be `nil` even after being assigned a value.
This commit is contained in:
parent
5b55aa52d0
commit
84b378b94f
1 changed files with 8 additions and 5 deletions
|
|
@ -1767,12 +1767,15 @@ further information.
|
||||||
Nil
|
Nil
|
||||||
---
|
---
|
||||||
|
|
||||||
If a reference points to *nothing*, it has the value ``nil``. ``nil`` is also
|
If a reference points to *nothing*, it has the value ``nil``. ``nil`` is the
|
||||||
the default value for all ``ref`` and ``ptr`` types. Dereferencing ``nil``
|
default value for all ``ref`` and ``ptr`` types. The ``nil`` value can also be
|
||||||
is an unrecoverable fatal runtime error (and not a panic).
|
used like any other literal value. For example, it can be used in an assignment
|
||||||
A dereferencing operation ``p[]`` implies that ``p`` is not nil. This can be
|
like ``myRef = nil``.
|
||||||
exploited by the implementation to optimize code like:
|
|
||||||
|
|
||||||
|
Dereferencing ``nil`` is an unrecoverable fatal runtime error (and not a panic).
|
||||||
|
|
||||||
|
A successful dereferencing operation ``p[]`` implies that ``p`` is not nil. This
|
||||||
|
can be exploited by the implementation to optimize code like:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue