Make function arguments positional or keyword

I’ve actually written a little package called RequiredKeywords.jl that implements this solution using a macro. You can use it like

julia> using RequiredKeywords

julia> @required_keywords f(x; y) = x*y
f (generic function with 1 method)

julia> f(2,y=2)
4

julia> f(2)
ERROR: Unassigned Keyword:  Required keyword y::Int64 not included.
Stacktrace:
 [1] f(::Int64) at ./REPL[5]:1

It also works for the longform function style definitions, and you can still specify types for the optional keyword arguments.

1 Like