Discard statement
Example:
proc p(x, y: int): int =
result = x + y
discard p(3, 4) # discard the return value of `p`
The discard statement evaluates its expression for side-effects and throws the expression’s resulting value away, and should only be used when ignoring this value is known not to cause problems.
Ignoring the return value of a procedure without using a discard statement is a static error.
The return value can be ignored implicitly if the called proc/iterator has been declared with the discardable pragma:
proc p(x, y: int): int {.discardable.} =
result = x + y
p(3, 4) # now valid
An empty discard statement is often used as a null statement:
proc classify(s: string) =
case s[0]
of SymChars, '_': echo "an identifier"
of '0'..'9': echo "a number"
else: discard
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .