indentation - Nim - 必须丢弃 int 的函数类型
问题描述
我是 Nim 的新手,为了好玩而写了这个简单的代码:
var x: int = 3
var y: int = 4
if true:
y = 7
else:
x = 7
proc hello(xx: int, yy: int, ): int =
return xx + yy
hello(x, y)
代码看起来不错(我检查了 Nim 手册),但它给出了这个奇怪的错误:
c:\Users\Xilpex\Desktop\Nim_tests\testrig.nim(12, 6) Error: expression 'hello(x, y)' is of type 'int' and has to be discarded
为什么我会收到此错误?有什么我可以解决的吗?
解决方案
您收到一个错误,因为声明为返回值的 procs 意味着在某处使用该值,因此编译器会提醒您忘记了调用的结果。如果有时您想要结果,而有时您想要忽略它,您可以使用丢弃语句或将 proc 声明为{.discardable.}
.
推荐阅读
- python - python 在通过 pip 安装时从 Tag 设置包版本
- flutter - Flutter Navigator 将类作为参数传递,无法获取参数属性,但是方法?
- c# - 当我的同一个实例被许多用户调用时,存储过程引发死锁
- spring-boot - 如何使用 Eureka 服务器将 Config Client 连接到 Config 服务器?
- stata - 如何使用 aweights 按年份计算标准差?
- python - 单击列表视图按钮切换到表单视图?在 Odoo V13 中
- ubuntu-20.04 - cloud-init 不会在自动安装结束时更新 ubuntu 包
- loopbackjs - 使用 Loopback 4 调用现有 API
- python - python中的单词标记化
- c - 使用 execvp 使用完整路径名错误执行命令行参数