Function dispatch ignores keyword arguments

Today I stumbled upon some weird Julia behavior. It seems that it is not possible to have multiple keyword-only functions with the same name. Is this a bug or intended behavior?

f1(;a,b) = println("a,b") # defines f1
f1(;a,b,c) = println("a,b,c") # redefines f1, deletes prev. definition
f1(;x,y) = println("x,y") # redefines f1, deletes prev. defintion

f1(x=1,y=2)     # works
f1(a=1,b=1,c=0) # fails, keyword `x` not assigned
f1(a=1,b=1)     # fails, keyword `x` not assigned

Thank you in advance!

That is intended.

2 Likes

The relevant part of the manual is Methods · The Julia Language.

Keyword arguments behave quite differently from ordinary positional arguments. In particular, they do not participate in method dispatch. Methods are dispatched based only on positional arguments, with keyword arguments processed after the matching method is identified.

3 Likes

Check out KeywordDispatch.jl

2 Likes