Dispatching functions and keyword usage

mrVeng
Fri, 15 Oct 2021 13:07:45 +0000
General Usage

Hi there,

Is there a way to dispatch on a function and still being able to call eventual keywords? I tried to dispatch a function, but could not call non-default keywords anymore afterwards.

MWE:

function testfn(a::Int64, b::Int64 , c::Int64; d = 5, e = 10)
    println( a + b + c)
    println(d)
    println(e)
end
testfn(1,2,3) # 6, 5, 10

#Now want to dispatch and keep keywords
testfn(c::Int64) = testfn(c, c, c)
testfn(1) #3, 5, 10

testfn(1; d = 1, e = 1) #MethodError: no method matching testfn(::Int64; d=1, e=1)

3 posts - 2 participants