Nim 团队已于上周发布了 Nim 0.20,官方表示这是一个重大更新版本,它包含超过 1000 个 commit,也算是标志着 1.0 候选版的推出。
Nim 0.20 引入了 1.0 所需的一些破坏性变更,这些变更将会被引入到 Nim 1.0 稳定版中,并且目前也没计划继续引入更多的破坏性变更。
所以 Nim 团队称这个版本为“事实上的 Nim 1.0 RC1”。他们还解释了为什么不直接发布
1.0,主要是希望社区能彻底测试 Nim 0.20,并找出可能是破坏性变更导致的 bug。更重要的是,1.0 的发布意味着 Nim
已到达一个稳定阶段,将不再进行任何重大的修改。所以团队希望在 0.20 基础上发布 1.0 候选版本,最终才是 1.0 稳定版。
Nim 0.20 新特性
not 永远是一元操作符
let a = false
assert not a
assert(not a)
assert not a
针对整数和浮点数转换进行更严格的编译时检查
const b = uint16(-1)
echo b
const b = uint16(-1)
const c = not uint16(0)
echo c
面向常量和for循环变量的元组拆包
const (d, e) = (7, "eight")
echo d
echo e
let f = @[(51, 10), (23, 25)]
for (x, y) in f:
echo x + y
默认情况下对哈希集和表进行初始化
import sets, tables
var s: HashSet[int]
s.incl(5)
echo s
var t: Table[char, int]
t['a'] = 10
echo t
针对 case 语句提供更友好的错误消息
type
MyEnum = enum
first
second
third
fourth
proc foo(x: MyEnum): int =
case x
of first: 1
of second: 2
of third: 3
of fourth: 4
else: 99
proc bar(x: MyEnum): int =
case x
of first: 1
of third: 3
在迭代期间,表的长度不得更改
import tables
var xs = {1: "one", 2: "two", 3: "three"}.toTable
for x in xs.keys:
if x mod 2 == 0:
xs[10*x] = "a lot"
echo xs
针对索引超出范围的情况,提供更友好的错误消息
let a = [10, 20, 30]
echo a[5]
# v0.19: Error: index out of bounds
# v0.20: Error: index 5 not in 0 .. 2
详细的更新日志和更新说明请查看发布公告。 |