Skip to content

Commit

Permalink
fix description of kwargs... (#28757)
Browse files Browse the repository at this point in the history
* fix description of kwargs...

* clarify the key type of dicts passed as kwargs

(cherry picked from commit 3a54c14)
  • Loading branch information
bicycle1885 authored and KristofferC committed Aug 20, 2018
1 parent d4c9d08 commit cfe7fcb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions doc/src/manual/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ function f(x; y=0, kwargs...)
end
```

Inside `f`, `kwargs` will be a key-value iterator over a named tuple. Named
tuples (as well as dictionaries with keys of `Symbol`) can be passed as keyword
arguments using a semicolon in a call, e.g. `f(x, z=1; kwargs...)`.

If a keyword argument is not assigned a default value in the method definition,
then it is *required*: an [`UndefKeywordError`](@ref) exception will be thrown
if the caller does not assign it a value:
Expand All @@ -552,9 +556,6 @@ f(3, y=5) # ok, y is assigned
f(3) # throws UndefKeywordError(:y)
```

Inside `f`, `kwargs` will be a named tuple. Named tuples (as well as dictionaries) can be passed as
keyword arguments using a semicolon in a call, e.g. `f(x, z=1; kwargs...)`.

One can also pass `key => value` expressions after a semicolon. For example, `plot(x, y; :width => 2)`
is equivalent to `plot(x, y, width=2)`. This is useful in situations where the keyword name is computed
at runtime.
Expand Down

0 comments on commit cfe7fcb

Please sign in to comment.