- Arrays of char cannot be converted to
cstring
anymore, pointers to arrays of char can! This means$
for arrays can finally exist insystem.nim
and do the right thing. echo
now works with strings that contain\0
(the binary zero is not shown) andnil
strings are equal to empty strings.- JSON: Deprecated
getBVal
,getFNum
, andgetNum
in favour togetBool
,getFloat
,getBiggestInt
. AlsogetInt
procedure was added. reExtended
is no longer default for there
constructor in there
module.- The overloading rules changed slightly so that constrained generics are preferred over unconstrained generics. (Bug #6526)
- It is now possible to forward declare object types so that mutually recursive types can be created across module boundaries. See package level objects for more information.
- The unary
<
is now deprecated, for.. <
use..<
for other usages use thepred
proc. - We changed how array accesses "from backwards" like
a[^1]
ora[0..^1]
are implemented. These are now implemented purely insystem.nim
without compiler support. There is a new "heterogenous" slice typesystem.HSlice
that takes 2 generic parameters which can beBackwardsIndex
indices.BackwardsIndex
is produced bysystem.^
. This means if you overload[]
or[]=
you need to ensure they also work withsystem.BackwardsIndex
(if applicable for the accessors). mod
and bitwiseand
do not producerange
subtypes anymore. This turned out to be more harmful than helpful and the language is simpler without this special typing rule.- Added
algorithm.rotateLeft
. rationals.toRational
now uses an algorithm based on continued fractions. This means its results are more precise and it can't run into an infinite loop anymore.- Added
typetraits.$
as an alias fortypetraits.name
. os.getEnv
now takes an optionaldefault
parameter that tellsgetEnv
what to return if the environment variable does not exist.- Bodies of
for
loops now get their own scope:
.. code-block:: nim
for i in 0..4: let i = i + 1 echo i
- The parsing rules of
if
expressions were changed so that multiple statements are allowed in the branches. We found few code examples that now fail because of this change, but here is one:
.. code-block:: nim
t[ti] = if exp_negative: '-' else: '+'; inc(ti)
This now needs to be written as:
.. code-block:: nim
t[ti] = (if exp_negative: '-' else: '+'); inc(ti)
- To make Nim even more robust the system iterators
..
andcountup
now only accept a single generic typeT
. This means the following code doesn't die with an "out of range" error anymore:
.. code-block:: nim
var b = 5.Natural var a = -5 for i in a..b: echo i
-
formatFloat
/formatBiggestFloat
now support formatting floats with zero precision digits. The previousprecision = 0
behavior (default formatting) is now available viaprecision = -1
. -
The
nim doc
command is now an alias fornim doc2
, the second version of the documentation generator. The old version 1 can still be accessed via the newnim doc0
command. -
Added
system.getStackTraceEntries
that allows you to access the stack trace in a structured manner without string parsing. -
Added
sequtils.mapLiterals
for easier construction of array and tuple literals. -
Added
parseutils.parseSaturatedNatural
. -
atomic
andgeneric
are no longer keywords in Nim.generic
used to be an alias forconcept
,atomic
was not used for anything. -
Moved from stdlib into Nimble packages:
-
Added
system.runnableExamples
to make examples in Nim's documentation easier to write and test. The examples are tested as the last step ofnim doc
. -
Nim's
rst2html
command now supports the testing of code snippets via an RST extension that we called:test:
::.. code-block:: nim :test: # shows how the 'if' statement works if true: echo "yes"
-
The
[]
proc for strings now raises anIndexError
exception when the specified slice is out of bounds. See issue #6223 for more details. -
strutils.split
andstrutils.rsplit
with an empty string and a separator now returns that empty string. See issue #4377. -
The experimental overloading of the dot
.
operators now take anuntyped``` parameter as the field name, it used to be a
static[string]. You can use
when defined(nimNewDot)`` to make your code work with both old and new Nim versions. See special-operators for more information. -
Added
macros.unpackVarargs
. -
The memory manager now uses a variant of the TLSF algorithm that has much better memory fragmentation behaviour. According to http://www.gii.upv.es/tlsf/ the maximum fragmentation measured is lower than 25%. As a nice bonus
alloc
anddealloc
became O(1) operations.