Hi all, I saw this code in Nim manual.
template t(body: untyped) =
proc p = echo "hey"
block:
body
t:
p() # compiles
I did some search in manual with the keyword "block" but didn't find any useful hint. What is this block keyword doing here ?Thanks for the reply. When I search with "block" I got this result
search results NimNodeKind.nnkPragmaBlock RstNodeKind.rnCodeBlock RstNodeKind.rnLineBlock RstNodeKind.rnLiteralBlock RstNodeKind.rnQuotedLiteralBlock htmlgen: blockquote(e: varargs[untyped]): untyped htmlparser: BlockTags threadpool: blockUntil(fv: var FlowVarBaseObj) threadpool: blockUntilAny(flowVars: openArray[FlowVarBase]): int macros: newBlockStmt(body: NimNode): NimNode macros: newBlockStmt(label, body: NimNode): NimNode nativesockets: setBlocking(s: SocketHandle; blocking: bool) NimNodeKind.nnkBlockExpr NimNodeKind.nnkBlockStmt NimNodeKind.nnkBlockType RstNodeKind.rnBlockQuote RstNodeKind.rnLineBlockItem HtmlTag.tagBlockquote winlean: WSAEWOULDBLOCK nativesockets: setInheritable(s: SocketHandle; inheritable: bool): bool dom: Blob
How can I understand which one is for the "block" keyword ?
block explicitly creates a new scope similar to putting arbitrary {..}s in C. They can also be named which allows for deep breaks. For example:
block bagels:
while true:
break bagels
echo "will never be echoed"
echo "no more bagels"