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:

This comment has been minimized.

Copy link
@yuyichao

yuyichao Jan 15, 2016

Contributor

I guess this should end with :: ?

This comment has been minimized.

Copy link
@tkelman

tkelman Jan 15, 2016

Contributor

if it makes the warning go away and looks right in the rendered result

This comment has been minimized.

Copy link
@hayd

hayd Jan 15, 2016

Author Member

Thanks for fixing this. Sorry I missed it.

Looking forward to the docs being pure markdown....

This comment has been minimized.

Copy link
@tkelman

tkelman Jan 15, 2016

Contributor

haven't pushed a fix yet? didn't check the rendering


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

This comment has been minimized.

Copy link
@tkelman

tkelman Jan 15, 2016

Contributor

sphinx is warning about bad rst here


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.