mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-01 19:02:18 +00:00
follow #11707(add pragmas examples for =>) (#15863)
(cherry picked from commit 9fd67958b9)
This commit is contained in:
@@ -57,12 +57,22 @@ proc createProcType(p, b: NimNode): NimNode {.compileTime.} =
|
||||
|
||||
macro `=>`*(p, b: untyped): untyped =
|
||||
## Syntax sugar for anonymous procedures.
|
||||
## It also supports pragmas.
|
||||
runnableExamples:
|
||||
proc passTwoAndTwo(f: (int, int) -> int): int =
|
||||
f(2, 2)
|
||||
|
||||
doAssert passTwoAndTwo((x, y) => x + y) == 4
|
||||
|
||||
type
|
||||
Bot = object
|
||||
call: proc (): string {.nosideEffect.}
|
||||
|
||||
var myBot = Bot()
|
||||
|
||||
myBot.call = () {.nosideEffect.} => "I'm a bot."
|
||||
doAssert myBot.call() == "I'm a bot."
|
||||
|
||||
var
|
||||
params = @[ident"auto"]
|
||||
name = newEmptyNode()
|
||||
|
||||
Reference in New Issue
Block a user