【发布时间】:2020-08-18 11:35:36
【问题描述】:
Nim 支持不带大括号的 proc 调用表达式,但是当我使用命名参数时它会报错,为什么?
proc doc(text: string) {.discardable.} = echo text
doc "doc1"
doc(text = "doc1")
doc text = "doc1" # <== Error here
【问题讨论】:
标签: nim-lang
Nim 支持不带大括号的 proc 调用表达式,但是当我使用命名参数时它会报错,为什么?
proc doc(text: string) {.discardable.} = echo text
doc "doc1"
doc(text = "doc1")
doc text = "doc1" # <== Error here
【问题讨论】:
标签: nim-lang
抱怨是Error: undeclared identifier: 'text',因为您调用doc proc 的值未声明。这有效:
proc doc(text: string) = echo text
let text = "doc1"
doc text
doc text = "doc1" 行告诉程序 1) 使用变量 text 作为第一个参数调用过程 doc 和 2) 将“doc1”分配给该过程返回的任何内容。所以你会发现错误Error: 'doc text' cannot be assigned to。
【讨论】: