Skip to content

Commit

Permalink
fix doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Jul 14, 2023
1 parent 26fd815 commit 76634c8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/spread.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ macro spread*(call: untyped, args: varargs[untyped]): untyped =
assert arr == [1, 2, 3]

# table constructors:
let tab = {:}.spread:
"a" = 1 # constructors convert = in a statement to :
_("b": 2, "c": 3) # all arguments of _ are spread directly
when false: # (nim doc renders badly)
let tab = {:}.spread:
"a" = 1 # constructors convert = in a statement to :
_("b": 2, "c": 3) # all arguments of _ are spread directly

assert tab == {"a": 1, "b": 2, "c": 3}
assert tab == {"a": 1, "b": 2, "c": 3}

# object or tuple constructors need a single `_: _``:
type Foo = object
Expand Down Expand Up @@ -75,6 +76,11 @@ macro spread*(call: untyped, args: varargs[untyped]): untyped =
template `...`*(call: untyped, args: varargs[untyped]): untyped =
## operator version of `spread`
runnableExamples:
proc foo(a, b, c: int) =
echo "a: ", a
echo "b: ", b
echo "c: ", c

...foo:
1
c = 3
Expand Down

0 comments on commit 76634c8

Please sign in to comment.