From this link, it says:
# You can define functions with optional positional arguments
function defaults(a,b,x=5,y=6)
return "$a $b and $x $y"
end
defaults('h','g') # => "h g and 5 6"
defaults('h','g','j') # => "h g and j 6"
defaults('h','g','j','k') # => "h g and j k"
try
defaults('h') # => ERROR: no method defaults(Char,)
defaults() # => ERROR: no methods defaults()
catch e
println(e)
end
I think the purpose of this example is to show that, if the provided arguments are less than the default ones, the function will also return the default ones.
But why the error appears when one or no argument is provided? i.e. how do I know that providing two arguments are okay, but providing one or none is not okay?