@@ -584,10 +584,12 @@ The destructuring feature can also be used within a function argument.
584584If a function argument name is written as a tuple (e.g. ` (x, y) ` ) instead of just
585585a symbol, then an assignment ` (x, y) = argument ` will be inserted for you:
586586
587- ``` julia-repl
587+ ``` jldoctest
588588julia> minmax(x, y) = (y < x) ? (y, x) : (x, y)
589+ minmax (generic function with 1 method)
589590
590591julia> gap((min, max)) = max - min
592+ gap (generic function with 1 method)
591593
592594julia> gap(minmax(10, 2))
5935958
@@ -598,7 +600,7 @@ would be a two-argument function, and this example would not work.
598600
599601Similarly, property destructuring can also be used for function arguments:
600602
601- ``` julia-repl
603+ ``` jldoctest
602604julia> foo((; x, y)) = x + y
603605foo (generic function with 1 method)
604606
@@ -616,7 +618,7 @@ julia> foo(A(3, 4))
616618
617619For anonymous functions, destructuring a single argument requires an extra comma:
618620
619- ``` julia-repl
621+ ``` jldoctest
620622julia> map(((x, y),) -> x + y, [(1, 2), (3, 4)])
6216232-element Vector{Int64}:
622624 3
@@ -784,12 +786,15 @@ Optional arguments are actually just a convenient syntax for writing multiple me
784786with different numbers of arguments (see [ Note on Optional and keyword Arguments] ( @ref ) ).
785787This can be checked for our ` date ` function example by calling the ` methods ` function:
786788
787- ``` julia-repl
789+ ``` jldoctest date_default_args; filter = r"@ .*"a
788790julia> methods(date)
789- # 3 methods for generic function "date":
790- [1] date(y::Int64) in Main at REPL[1]:1
791- [2] date(y::Int64, m::Int64) in Main at REPL[1]:1
792- [3] date(y::Int64, m::Int64, d::Int64) in Main at REPL[1]:1
791+ # 3 methods for generic function "date" from Main:
792+ [1] date(y::Int64, m::Int64, d::Int64)
793+ @ REPL[2]:1
794+ [2] date(y::Int64, m::Int64)
795+ @ REPL[2]:1
796+ [3] date(y::Int64)
797+ @ REPL[2]:1
793798```
794799
795800## Keyword Arguments
0 commit comments