How to define a function with more than one optional arguments in Julia?

julia> xyzpos(x, y, z=0) = x,y,z
xyzpos (generic function with 2 methods)

julia> xyzpos(1,2,z=3)
ERROR: MethodError: no method matching xyzpos(::Int64, ::Int64; z=3)
Closest candidates are:

this shouldn’t work, if you don’t have ;, you simply don’t have keyword argument, so what you want is:

function xyzpos(; x, y, z=0)
    println("$x, $y, $z")
end

notice the ;

1 Like