为什么不戴牙套就不能叫Nim proc?

问题描述

Nim支持proc调用不带花括号的表达式,但是当我使用命名参数时会抱怨为什么?

proc doc(text: string) {.discardable.} = echo text
doc "doc1"
doc(text = "doc1")
doc text = "doc1" # <== Error here

解决方法

抱怨是Error: undeclared identifier: 'text',因为您正在使用未声明的值调用doc proc。这有效:

proc doc(text: string) = echo text

let text = "doc1"
doc text

doc text = "doc1"告诉程序1)以变量doc作为第一个参数调用过程text,并2)将“ doc1”分配给该过程返回的任何内容。因此,您会发现错误Error: 'doc text' cannot be assigned to