follow #11707(add pragmas examples for =>) (#15863)
This commit is contained in:
parent
218ff27b70
commit
9fd67958b9
1 changed files with 10 additions and 0 deletions
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue