Typical Quarts in Julia

Can i introduce kwargs function in Julia?

The following works for standard Varargs.

function int_args(args::Integer...)
    args
end

int_args(1, 2, 3)
# (1, 2, 3)

int_args(1, 2, 3.0)
# ERROR: MethodError: `int_args` has no method matching int_args(::Int64, ::Int64, ::Float64)

However, when applying the same syntax to kwargs, all function calls seem to be an error.

function int_kwargs(; kwargs::Integer...)
    kwargs
end

int_kwargs(x=1, y=2)
# ERROR: MethodError: `__int_kwargs#0__` has no method matching __int_kwargs#0__(::Array{Any,1})
+4
source share
1 answer

Regular keyword arguments can have types, as in function f(x; a::Int=0), but this does not work for the rest keyword arguments. Also note that since we are not currently sending keyword arguments, a::Intin this case it is a type statement and not a sending specification.

, , , . https://github.com/JuliaLang/julia/issues.

, x::T... . varargs , x T, rest - . , , ( T), , , . , , , varargs, .

+9

Source: https://habr.com/ru/post/1653080/


All Articles