Skip to content

Commit

Permalink
Document how to make a kwarg's type explicit.
Browse files Browse the repository at this point in the history
[ci-skip]
  • Loading branch information
hayd committed Jan 11, 2016
1 parent b9dc4c9 commit ce9d225
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions doc/manual/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -476,19 +476,25 @@ Keyword argument default values are evaluated only when necessary
left-to-right order. Therefore default expressions may refer to
prior keyword arguments.

The types of keyword arguments can be made explicit as follows:

function f(;x::Int64=1)
###
end

Extra keyword arguments can be collected using ``...``, as in varargs
functions::

function f(x; y=0, args...)
function f(x; y=0, kwargs...)
###
end

Inside ``f``, ``args`` will be a collection of ``(key,value)`` tuples,
Inside ``f``, ``kwargs`` will be a collection of ``(key,value)`` tuples,
where each ``key`` is a symbol. Such collections can be passed as keyword
arguments using a semicolon in a call, e.g. ``f(x, z=1; args...)``.
arguments using a semicolon in a call, e.g. ``f(x, z=1; kwargs...)``.
Dictionaries can also be used for this purpose.

In addition, one can also pass ``(key,value)`` tuples, or any iterable
One can also pass ``(key,value)`` tuples, or any iterable
expression (such as a ``=>`` pair) that can be assigned to such a
tuple, explicitly after a semicolon. For example, ``plot(x, y;
(:width,2))`` and ``plot(x, y; :width => 2)`` are equivalent to
Expand Down

0 comments on commit ce9d225

Please sign in to comment.