|
2 | 2 |
|
3 | 3 | ### Changes affecting backwards compatibility
|
4 | 4 |
|
5 |
| -- Removed basic2d/basic3d out of the stdlib and into Nimble packages. |
6 |
| - These packages deprecated however, use the ``glm``, ``arraymancer``, ``neo`` |
7 |
| - or another package. |
| 5 | + |
8 | 6 | - Arrays of char cannot be converted to ``cstring`` anymore, pointers to
|
9 | 7 | arrays of char can! This means ``$`` for arrays can finally exist
|
10 | 8 | in ``system.nim`` and do the right thing.
|
11 |
| -- JSON: Deprecated `getBVal`, `getFNum`, and `getNum` in favour to |
12 |
| - `getBool`, `getFloat`, `getBiggestInt`. Also `getInt` procedure was added. |
| 9 | +- ``echo`` now works with strings that contain ``\0`` (the binary zero is not |
| 10 | + shown) and ``nil`` strings are equal to empty strings. |
| 11 | +- JSON: Deprecated `getBVal`, `getFNum`, and `getNum` in favour to |
| 12 | + `getBool`, `getFloat`, `getBiggestInt`. Also `getInt` procedure was added. |
| 13 | +- `reExtended` is no longer default for the `re` constructor in the `re` |
| 14 | + module. |
| 15 | +- The overloading rules changed slightly so that constrained generics are |
| 16 | + preferred over unconstrained generics. (Bug #6526) |
| 17 | +- It is now possible to forward declare object types so that mutually |
| 18 | + recursive types can be created across module boundaries. See |
| 19 | + [package level objects](https://nim-lang.org/docs/manual.html#package-level-objects) |
| 20 | + for more information. |
| 21 | +- The **unary** ``<`` is now deprecated, for ``.. <`` use ``..<`` for other usages |
| 22 | + use the ``pred`` proc. |
| 23 | +- We changed how array accesses "from backwards" like ``a[^1]`` or ``a[0..^1]`` are |
| 24 | + implemented. These are now implemented purely in ``system.nim`` without compiler |
| 25 | + support. There is a new "heterogenous" slice type ``system.HSlice`` that takes 2 |
| 26 | + generic parameters which can be ``BackwardsIndex`` indices. ``BackwardsIndex`` is |
| 27 | + produced by ``system.^``. |
| 28 | + This means if you overload ``[]`` or ``[]=`` you need to ensure they also work |
| 29 | + with ``system.BackwardsIndex`` (if applicable for the accessors). |
| 30 | +- ``mod`` and bitwise ``and`` do not produce ``range`` subtypes anymore. This |
| 31 | + turned out to be more harmful than helpful and the language is simpler |
| 32 | + without this special typing rule. |
| 33 | +- Added ``algorithm.rotateLeft``. |
| 34 | +- ``rationals.toRational`` now uses an algorithm based on continued fractions. |
| 35 | + This means its results are more precise and it can't run into an infinite loop |
| 36 | + anymore. |
| 37 | +- Added ``typetraits.$`` as an alias for ``typetraits.name``. |
| 38 | +- ``os.getEnv`` now takes an optional ``default`` parameter that tells ``getEnv`` |
| 39 | + what to return if the environment variable does not exist. |
| 40 | +- Bodies of ``for`` loops now get their own scope: |
| 41 | + |
| 42 | +```nim |
| 43 | + # now compiles: |
| 44 | + for i in 0..4: |
| 45 | + let i = i + 1 |
| 46 | + echo i |
| 47 | +``` |
| 48 | + |
| 49 | +- The parsing rules of ``if`` expressions were changed so that multiple |
| 50 | + statements are allowed in the branches. We found few code examples that |
| 51 | + now fail because of this change, but here is one: |
| 52 | + |
| 53 | +```nim |
| 54 | + t[ti] = if exp_negative: '-' else: '+'; inc(ti) |
| 55 | +``` |
| 56 | + |
| 57 | +This now needs to be written as: |
| 58 | + |
| 59 | +```nim |
| 60 | + t[ti] = (if exp_negative: '-' else: '+'); inc(ti) |
| 61 | +``` |
| 62 | + |
| 63 | +- To make Nim even more robust the system iterators ``..`` and ``countup`` |
| 64 | + now only accept a single generic type ``T``. This means the following code |
| 65 | + doesn't die with an "out of range" error anymore: |
| 66 | + |
| 67 | +```nim |
| 68 | + var b = 5.Natural |
| 69 | + var a = -5 |
| 70 | + for i in a..b: |
| 71 | + echo i |
| 72 | +``` |
| 73 | + |
| 74 | +- ``formatFloat``/``formatBiggestFloat`` now support formatting floats with zero |
| 75 | + precision digits. The previous ``precision = 0`` behavior (default formatting) |
| 76 | + is now available via ``precision = -1``. |
| 77 | +- The ``nim doc`` command is now an alias for ``nim doc2``, the second version of |
| 78 | + the documentation generator. The old version 1 can still be accessed |
| 79 | + via the new ``nim doc0`` command. |
| 80 | +- Added ``system.getStackTraceEntries`` that allows you to access the stack |
| 81 | + trace in a structured manner without string parsing. |
| 82 | +- Added ``sequtils.mapLiterals`` for easier construction of array and tuple |
| 83 | + literals. |
| 84 | +- Added ``parseutils.parseSaturatedNatural``. |
| 85 | +- ``atomic`` and ``generic`` are no longer keywords in Nim. ``generic`` used to be |
| 86 | + an alias for ``concept``, ``atomic`` was not used for anything. |
| 87 | +- Moved from stdlib into Nimble packages: |
| 88 | + - [``basic2d``](https://github.com/nim-lang/basic2d) |
| 89 | + _deprecated: use ``glm``, ``arraymancer``, ``neo``, or another package instead_ |
| 90 | + - [``basic3d``](https://github.com/nim-lang/basic3d) |
| 91 | + _deprecated: use ``glm``, ``arraymancer``, ``neo``, or another package instead_ |
| 92 | + - [``gentabs``](https://github.com/lcrees/gentabs) |
| 93 | + - [``libuv``](https://github.com/lcrees/libuv) |
| 94 | + - [``numeric``](https://github.com/lcrees/polynumeric) |
| 95 | + - [``poly``](https://github.com/lcrees/polynumeric) |
| 96 | + - [``pdcurses``](https://github.com/lcrees/pdcurses) |
| 97 | + - [``romans``](https://github.com/lcrees/romans) |
| 98 | + |
| 99 | +- Added ``system.runnableExamples`` to make examples in Nim's documentation easier |
| 100 | + to write and test. The examples are tested as the last step of |
| 101 | + ``nim doc``. |
| 102 | +- Nim's ``rst2html`` command now supports the testing of code snippets via an RST |
| 103 | + extension that we called ``:test:``:: |
| 104 | + |
| 105 | + ```rst |
| 106 | + .. code-block:: nim |
| 107 | + :test: |
| 108 | + # shows how the 'if' statement works |
| 109 | + if true: echo "yes" |
| 110 | + ``` |
| 111 | +- The ``[]`` proc for strings now raises an ``IndexError`` exception when |
| 112 | + the specified slice is out of bounds. See issue |
| 113 | + [#6223](https://github.com/nim-lang/Nim/issues/6223) for more details. |
| 114 | + You can use ``substr(str, start, finish)`` to get the old behaviour back, |
| 115 | + see [this commit](https://github.com/nim-lang/nimbot/commit/98cc031a27ea89947daa7f0bb536bcf86462941f) for an example. |
| 116 | +- ``strutils.split`` and ``strutils.rsplit`` with an empty string and a |
| 117 | + separator now returns that empty string. |
| 118 | + See issue [#4377](https://github.com/nim-lang/Nim/issues/4377). |
| 119 | +- The experimental overloading of the dot ``.`` operators now take |
| 120 | + an ``untyped``` parameter as the field name, it used to be |
| 121 | + a ``static[string]``. You can use ``when defined(nimNewDot)`` to make |
| 122 | + your code work with both old and new Nim versions. |
| 123 | + See [special-operators](https://nim-lang.org/docs/manual.html#special-operators) |
| 124 | + for more information. |
| 125 | +- Added ``macros.unpackVarargs``. |
| 126 | +- The memory manager now uses a variant of the TLSF algorithm that has much |
| 127 | + better memory fragmentation behaviour. According |
| 128 | + to [http://www.gii.upv.es/tlsf/](http://www.gii.upv.es/tlsf/) the maximum |
| 129 | + fragmentation measured is lower than 25%. As a nice bonus ``alloc`` and |
| 130 | + ``dealloc`` became O(1) operations. |
| 131 | +- The behavior of ``$`` has been changed for all standard library collections. The |
| 132 | + collection-to-string implementations now perform proper quoting and escaping of |
| 133 | + strings and chars. |
| 134 | +- The ``random`` procs in ``random.nim`` have all been deprecated. Instead use |
| 135 | + the new ``rand`` procs. The module now exports the state of the random |
| 136 | + number generator as type ``Rand`` so multiple threads can easily use their |
| 137 | + own random number generators that do not require locking. For more information |
| 138 | + about this rename see issue [#6934](https://github.com/nim-lang/Nim/issues/6934) |
| 139 | +- The compiler is now more consistent in its treatment of ambiguous symbols: |
| 140 | + Types that shadow procs and vice versa are marked as ambiguous (bug #6693). |
| 141 | +- ``yield`` (or ``await`` which is mapped to ``yield``) never worked reliably |
| 142 | + in an array, seq or object constructor and is now prevented at compile-time. |
| 143 | +- For string formatting / interpolation a new module |
| 144 | + called [strformat](https://nim-lang.org/docs/strformat.html) has been added |
| 145 | + to the stdlib. |
| 146 | +- codegenDecl pragma now works for the JavaScript backend. It returns an empty string for |
| 147 | + function return type placeholders. |
| 148 | +- Asynchronous programming for the JavaScript backend using the `asyncjs` module. |
| 149 | +- Extra semantic checks for procs with noreturn pragma: return type is not allowed, |
| 150 | + statements after call to noreturn procs are no longer allowed. |
| 151 | +- Noreturn proc calls and raising exceptions branches are now skipped during common type |
| 152 | + deduction in if and case expressions. The following code snippets now compile: |
| 153 | +```nim |
| 154 | +import strutils |
| 155 | +let str = "Y" |
| 156 | +let a = case str: |
| 157 | + of "Y": true |
| 158 | + of "N": false |
| 159 | + else: raise newException(ValueError, "Invalid boolean") |
| 160 | +let b = case str: |
| 161 | + of nil, "": raise newException(ValueError, "Invalid boolean") |
| 162 | + elif str.startsWith("Y"): true |
| 163 | + elif str.startsWith("N"): false |
| 164 | + else: false |
| 165 | +let c = if str == "Y": true |
| 166 | + elif str == "N": false |
| 167 | + else: |
| 168 | + echo "invalid bool" |
| 169 | + quit("this is the end") |
| 170 | +``` |
| 171 | +- Proc [toCountTable](https://nim-lang.org/docs/tables.html#toCountTable,openArray[A]) now produces a `CountTable` with values correspoding to the number of occurrences of the key in the input. It used to produce a table with all values set to `1`. |
| 172 | + |
| 173 | +Counting occurrences in a sequence used to be: |
| 174 | + |
| 175 | +```nim |
| 176 | +let mySeq = @[1, 2, 1, 3, 1, 4] |
| 177 | +var myCounter = initCountTable[int]() |
| 178 | +
|
| 179 | +for item in mySeq: |
| 180 | + myCounter.inc item |
| 181 | +``` |
| 182 | + |
| 183 | +Now, you can simply do: |
| 184 | + |
| 185 | +```nim |
| 186 | +let |
| 187 | + mySeq = @[1, 2, 1, 3, 1, 4] |
| 188 | + myCounter = mySeq.toCountTable() |
| 189 | +``` |
| 190 | + |
| 191 | +- Added support for casting between integers of same bitsize in VM (compile time and nimscript). |
| 192 | + This allow to among other things to reinterpret signed integers as unsigned. |
0 commit comments