103
103
will raise a run-time error if the value is not of the expected type,
104
104
potentially catching certain bugs earlier.
106
Declare types of named arguments
106
Declare types of keyword arguments
107
107
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109
Named arguments can have declared types::
109
Keyword arguments can have declared types::
111
function with_named(x; name::Int = 1)
111
function with_keyword(x; name::Int = 1)
115
Functions are specialized on the types of named arguments, so these
115
Functions are specialized on the types of keyword arguments, so these
116
116
declarations will not affect performance of code inside the function.
117
117
However, they will reduce the overhead of calls to the function that
118
include named arguments.
118
include keyword arguments.
120
Functions with named arguments have near-zero overhead for call sites
120
Functions with keyword arguments have near-zero overhead for call sites
121
121
that pass only positional arguments.
123
Passing dynamic lists of named arguments, as in ``f(x; names...)``,
123
Passing dynamic lists of keyword arguments, as in ``f(x; keywords...)``,
124
124
can be slow and should be avoided in performance-sensitive code.
126
126
Break functions into multiple definitions