@@ -584,10 +584,12 @@ The destructuring feature can also be used within a function argument.
584
584
If a function argument name is written as a tuple (e.g. ` (x, y) ` ) instead of just
585
585
a symbol, then an assignment ` (x, y) = argument ` will be inserted for you:
586
586
587
- ``` julia-repl
587
+ ``` jldoctest
588
588
julia> minmax(x, y) = (y < x) ? (y, x) : (x, y)
589
+ minmax (generic function with 1 method)
589
590
590
591
julia> gap((min, max)) = max - min
592
+ gap (generic function with 1 method)
591
593
592
594
julia> gap(minmax(10, 2))
593
595
8
@@ -598,7 +600,7 @@ would be a two-argument function, and this example would not work.
598
600
599
601
Similarly, property destructuring can also be used for function arguments:
600
602
601
- ``` julia-repl
603
+ ``` jldoctest
602
604
julia> foo((; x, y)) = x + y
603
605
foo (generic function with 1 method)
604
606
@@ -616,7 +618,7 @@ julia> foo(A(3, 4))
616
618
617
619
For anonymous functions, destructuring a single argument requires an extra comma:
618
620
619
- ``` julia-repl
621
+ ``` jldoctest
620
622
julia> map(((x, y),) -> x + y, [(1, 2), (3, 4)])
621
623
2-element Vector{Int64}:
622
624
3
@@ -784,12 +786,15 @@ Optional arguments are actually just a convenient syntax for writing multiple me
784
786
with different numbers of arguments (see [ Note on Optional and keyword Arguments] ( @ref ) ).
785
787
This can be checked for our ` date ` function example by calling the ` methods ` function:
786
788
787
- ``` julia-repl
789
+ ``` jldoctest date_default_args; filter = r"@ .*"a
788
790
julia> 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
793
798
```
794
799
795
800
## Keyword Arguments
0 commit comments