命令式编程语言Nim 0.20发布,1.0 还会远吗?
2019-06-14 20:10
1286 查看
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
# v0.19:
assert not a # Error: type mismatch: got <proc (cond: untyped, msg: string): typed, bool>
assert(not a) # workaround
# v0.20:
assert not a
针对整数和浮点数转换进行更严格的编译时检查
# v0.19:
const b = uint16(-1)
echo b # 65535
# v0.20:
const b = uint16(-1)
# Error: -1 can't be converted to uint16
const c = not uint16(0)
echo c # 65535
面向常量和for循环变量的元组拆包
const (d, e) = (7, "eight")
# v0.19: Error: identifier expected, but got '('
# v0.20:
echo d # 7
echo e # eight
let f = @[(51, 10), (23, 25)]
for (x, y) in f: # v0.19: Error: identifier expected, but got '('
echo x + y
# v0.20:
# 61
# 48
默认情况下对哈希集和表进行初始化
import sets, tables
var s: HashSet[int]
s.incl(5)
# v0.19: `isValid(s)` Error: unhandled exception: The set needs to be initialized. [AssertionError]
# v0.20:
echo s # {5}
var t: Table[char, int]
t['a'] = 10
# v0.19: Error: unhandled exception: index out of bounds [IndexError]
# v0.20:
echo t # {'a': 10}
针对 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
# v0.19: compiles
# v0.20: Error: invalid else, all cases are already covered
proc bar(x: MyEnum): int =
case x
of first: 1
of third: 3
# v0.19: Error: not all cases are covered
# v0.20: Error: not all cases are covered; missing: {second, fourth}
在迭代期间,表的长度不得更改
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
# v0.19: {200: "a lot", 1: "one", 2: "two", 3: "three", 20: "a lot"}
# v0.20: Error: unhandled exception: the length of the table changed while iterating over it [AssertionError]
针对索引超出范围的情况,提供更友好的错误消息
let a = [10, 20, 30]
echo a[5]
# v0.19: Error: index out of bounds
# v0.20: Error: index 5 not in 0 .. 2
详细的更新日志和更新说明请查看「阅读原文」。
开源中国征稿啦!
开源中国 www.oschina.net 是目前备受关注、具有强大影响力的开源技术社区,拥有超过 400 万的开源技术精英。我们传播开源的理念,推广开源项目,为 IT 开发者提供一个发现、使用、并交流开源技术的平台。
现在我们开始对外征稿啦!如果你有优秀的技术文章想要分享,热点的行业资讯需要报道等等,欢迎联系开源中国进行投稿。投稿详情及联系方式请参见:我要投稿
相关文章推荐
- PySide: Python for Qt 1.0发布 - 编程语言 - ITeye资讯
- Rust 0.2 发布,Mozilla 的编程语言
- 云应用开发工具:Spring Cloud 1.0 正式发布
- [Android应用]《花界》V1.0 正式版隆重发布!
- EasyWork项目管理系统1.0测试版正式发布
- Django 1.0 中文文档-----指导 第三部分 发布视图
- Mac OS X原生开源游戏模拟器OpenEmu 1.0版本发布
- Silverlight 1.0正式发布了,并支持Linux
- [代码发布]中文文字转换组件 1.0,支持VB/ASP编程
- Visual Studio 2005 Web Application Project 1.0 正式发布
- 苹果编程语言 Swift 2.2 发布:支持 Ubuntu Linux 系统
- 跨年呈献:HP-Socket for Linux 1.0 震撼发布
- ASP.NET MVC 1.0 发布了
- 2012 9月TIOBE 编程社区发布编程语言使用排行
- 基于.NET的AOP开源框架PostSharp 1.0 beta发布
- Silverlight 4 Tools for Visual Studio 2010 和 WCF RIA Services 1.0发布
- PyTorch 1.0 预览版发布:Facebook 最新 AI 开源框架
- iKcamp出品|微信小程序|小试牛刀(视频)+发布流程|基于最新版1.0开发者工具初中级教程分享
- ASP.NET MVC 1.0 发布了[转]
- 微软发布ASP.NET MVC 1.0正式版