follow #11707(add pragmas examples for =>) (#15863)

This commit is contained in:
flywind 2020-11-06 18:42:43 +08:00 • committed by GitHub
commit 9fd67958b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,12 +57,22 @@ proc createProcType(p, b: NimNode): NimNode {.compileTime.} =
macro `=>`*(p, b: untyped): untyped = macro `=>`*(p, b: untyped): untyped =
## Syntax sugar for anonymous procedures. ## Syntax sugar for anonymous procedures.
## It also supports pragmas.
runnableExamples: runnableExamples:
proc passTwoAndTwo(f: (int, int) -> int): int = proc passTwoAndTwo(f: (int, int) -> int): int =
f(2, 2) f(2, 2)
doAssert passTwoAndTwo((x, y) => x + y) == 4 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 var
params = @[ident"auto"] params = @[ident"auto"]
name = newEmptyNode() name = newEmptyNode()