# Keyword name disambiguation

**URL:** <https://discourse.julialang.org/t/keyword-name-disambiguation/5459>\
**Category:** General Usage\
**Created:** [August 19, 2017, 11:52am UTC](https://discourse.julialang.org/t/keyword-name-disambiguation/5459 "2017-08-19T11:52:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [August 19, 2017, 11:52am UTC](https://discourse.julialang.org/t/keyword-name-disambiguation/5459/1 "2017-08-19T11:52:26Z")

</div>

I’ working on a code which, for the sake of clarity, has long keyword names.  
A simple example is:

```julia
function foo(;ABooleanKeyword=false, AnotherLooongKeyword=2)
    println(ABooleanKeyword)
    println(AnotherLooongKeyword)
end

```

Is there a simply way to call the `foo` function with abbreviated keyword names, such as `foo(ABoo=true, Another=4)` ?  
There would be no ambiguity in this case…

Also, since the default value of the first keyword is a boolean, it would be nice and clear (IMHO) if I could use it as an on/off switch being on when the keyword is provided, off otherwise, i.e.

```julia
foo(ABoo) ==> ON
foo() ==> OFF

```

In the first case there would be an ambiguity on whether `ABoo` is the keyword or another symbol. However, a syntax similar to `foo(/ABoo)`, `foo(>ABoo)`, `foo(;ABoo)` etc… would remove any ambiguity.

Is there a simple way to do this already implemented in Julia ?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 19, 2017, 1:25pm UTC](https://discourse.julialang.org/t/keyword-name-disambiguation/5459/2 "2017-08-19T13:25:48Z")

</div>

This mechanism reminds me of R, but AFAICT Julia has nothing similar, and implementing this would require complex macrology/introspection.

In Julia, it is common practice to wrap up bundles of repeated keyword parameters in a structure.

---

<div class="post-metadata">

**Author:** ![kevin.squire](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevin.squire/32/62_2.png) [@kevin.squire](https://discourse.julialang.org/u/kevin.squire)\
**Post date:** [August 19, 2017, 2:05pm UTC](https://discourse.julialang.org/t/keyword-name-disambiguation/5459/3 "2017-08-19T14:05:59Z")

</div>

I believe Plots.jl does allow for various keyword argument aliases, but I’m unsure  
how it does this.

Cheers,  
Kevin

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [August 19, 2017, 2:09pm UTC](https://discourse.julialang.org/t/keyword-name-disambiguation/5459/4 "2017-08-19T14:09:19Z")

</div>

> [@Tamas\_Papp](#):
>
> In Julia, it is common practice to wrap up bundles of repeated keyword parameters in a structure.

Isn’t that for when you have _many_ parameters? The problem here is the length of the names.

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [August 21, 2017, 9:03pm UTC](https://discourse.julialang.org/t/keyword-name-disambiguation/5459/5 "2017-08-21T21:03:14Z")

</div>

I created a small macro to fulfill my purpose. It is available as a package here:  
[https://github.com/gcalderone/AbbrvKW.jl](https://github.com/gcalderone/AbbrvKW.jl)

To use it go from:

```julia
function Foo(; Keyword1::Int=1, AnotherKeyword::Float64=2.0, StillAnotherOne=3, KeyString::String="bar")
...
end

```

to:

```julia
using AbbrvKW

function Foo(; kw...)
    @AbbrvKW(kw, Keyword1::Int=1, AnotherKeyword::Float64=2.0, StillAnotherOne=3, KeyString::String="bar")
   ...
end

```

This way I can call the `Foo` function with abbreviated keyword names, as long as the provided names allow complete disambiguation, i.e.:

```julia
Foo(Keyw=10, A=20.0, S=30, KeyS="baz")

```

I would like to see this functionality included as a native feature in future versions of Julia, but I have no idea on how to implement it, nor how much effort it requires… ☹

Comments/suggestions are welcome!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 22, 2017, 1:23am UTC](https://discourse.julialang.org/t/keyword-name-disambiguation/5459/6 "2017-08-22T01:23:26Z")

</div>

> [@kevin.squire](#):
>
> I believe Plots.jl does allow for various keyword argument aliases, but I’m unsure
> 
> how it does this.

Lots of dictionaries: [https://github.com/JuliaPlots/Plots.jl/blob/master/src/args.jl](https://github.com/JuliaPlots/Plots.jl/blob/master/src/args.jl) . ODEInterfaceDiffEq.jl does it similarly in order to translate DiffEq commands to ODEInterface.jl: [https://github.com/JuliaDiffEq/ODEInterfaceDiffEq.jl/blob/master/src/solve.jl#L138](https://github.com/JuliaDiffEq/ODEInterfaceDiffEq.jl/blob/master/src/solve.jl#L138)

This idea works well en masse, but if just handling a few args it would be tedious at best.
