From 096dd4f38504bf295ad82c101e4b472aa4a28084 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 16 Dec 2019 17:08:00 +0100 Subject: [PATCH] Update operators for 0.6.0. --- docs/types/operators.rst | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/types/operators.rst b/docs/types/operators.rst index f53d6ee57..c65e545c5 100644 --- a/docs/types/operators.rst +++ b/docs/types/operators.rst @@ -3,9 +3,14 @@ Operators Involving LValues =========================== -If ``a`` is an LValue (i.e. a variable or something that can be assigned to), the following operators are available as shorthands: +If ``a`` is an LValue (i.e. a variable or something that can be assigned to), the +following operators are available as shorthands: -``a += e`` is equivalent to ``a = a + e``. The operators ``-=``, ``*=``, ``/=``, ``%=``, ``|=``, ``&=`` and ``^=`` are defined accordingly. ``a++`` and ``a--`` are equivalent to ``a += 1`` / ``a -= 1`` but the expression itself still has the previous value of ``a``. In contrast, ``--a`` and ``++a`` have the same effect on ``a`` but return the value after the change. +``a += e`` is equivalent to ``a = a + e``. The operators ``-=``, ``*=``, ``/=``, ``%=``, +``|=``, ``&=`` and ``^=`` are defined accordingly. ``a++`` and ``a--`` are equivalent +to ``a += 1`` / ``a -= 1`` but the expression itself still has the previous value +of ``a``. In contrast, ``--a`` and ``++a`` have the same effect on ``a`` but +return the value after the change. .. _delete: @@ -19,12 +24,20 @@ initial value. ``delete a[x]`` deletes the item at index ``x`` of the array and all other elements and the length of the array untouched. This especially means that it leaves a gap in the array. If you plan to remove items, a :ref:`mapping ` is probably a better choice. -For structs, it assigns a struct with all members reset. In other words, the value of ``a`` after ``delete a`` is the same as if ``a`` would be declared without assignment, with the following caveat: +For structs, it assigns a struct with all members reset. In other words, +the value of ``a`` after ``delete a`` is the same as if ``a`` would be declared +without assignment, with the following caveat: -``delete`` has no effect on mappings (as the keys of mappings may be arbitrary and are generally unknown). So if you delete a struct, it will reset all members that are not mappings and also recurse into the members unless they are mappings. However, individual keys and what they map to can be deleted: If ``a`` is a mapping, then ``delete a[x]`` will delete the value stored at ``x``. +``delete`` has no effect on mappings (as the keys of mappings may be arbitrary and +are generally unknown). So if you delete a struct, it will reset all members that +are not mappings and also recurse into the members unless they are mappings. +However, individual keys and what they map to can be deleted: If ``a`` is a +mapping, then ``delete a[x]`` will delete the value stored at ``x``. -It is important to note that ``delete a`` really behaves like an assignment to ``a``, i.e. it stores a new object in ``a``. -This distinction is visible when ``a`` is reference variable: It will only reset ``a`` itself, not the +It is important to note that ``delete a`` really behaves like an +assignment to ``a``, i.e. it stores a new object in ``a``. +This distinction is visible when ``a`` is reference variable: It +will only reset ``a`` itself, not the value it referred to previously. ::