# Kwargs for getindex with ;

**URL:** <https://discourse.julialang.org/t/kwargs-for-getindex-with/18239>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [December 3, 2018, 9:31am UTC](https://discourse.julialang.org/t/kwargs-for-getindex-with/18239 "2018-12-03T09:31:21Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [December 3, 2018, 9:31am UTC](https://discourse.julialang.org/t/kwargs-for-getindex-with/18239/1 "2018-12-03T09:31:21Z")

</div>

Since this is a corner case of syntax, I am asking here before opening an issue.

Keyword args are allowed for `getindex` since [#25631](https://github.com/JuliaLang/julia/issues/25631) was fixed. But including an explicit `;` causes problems:

```julia
julia> VERSION
v"1.1.0-DEV.785"

julia> struct Foo end

julia> f = Foo()
Foo()

julia> Base.getindex(::Foo, args...; kwargs...) = (args, kwargs)

julia> f[1, bar = 4]
((1,), Base.Iterators.Pairs(:bar=>4))

julia> f[bar = 4]
((), Base.Iterators.Pairs(:bar=>4))

julia> f[1; bar = 4]
ERROR: syntax: misplaced assignment statement in "f[1; bar = 4]"

julia> f[; bar = 4]
ERROR: syntax: unexpected ";"

```

Is this a bug?

---

<div class="post-metadata">

**Author:** ![y4lu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@y4lu](https://discourse.julialang.org/u/y4lu)\
**Post date:** [December 3, 2018, 2:51pm UTC](https://discourse.julialang.org/t/kwargs-for-getindex-with/18239/2 "2018-12-03T14:51:52Z")

</div>

Could be ambiguous with the `[1; 2]` syntax.

```julia
f[(1; b=2)]
>((2,), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}())
```

---

<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:** [December 3, 2018, 3:27pm UTC](https://discourse.julialang.org/t/kwargs-for-getindex-with/18239/3 "2018-12-03T15:27:41Z")

</div>

> [@y4lu](#):
>
> Could be ambiguous with the `[1; 2]` syntax.

Unfortunately, yes. But the `()` workaround you suggested is fine, thanks!

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 3, 2018, 4:18pm UTC](https://discourse.julialang.org/t/kwargs-for-getindex-with/18239/4 "2018-12-03T16:18:19Z")

</div>

> [@Tamas\_Papp](#):
>
> Unfortunately, yes. But the `()` workaround you suggested is fine, thanks!

It doesn’t. It’s simply `2`.

---

<div class="post-metadata">

**Author:** ![y4lu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@y4lu](https://discourse.julialang.org/u/y4lu)\
**Post date:** [December 4, 2018, 12:26am UTC](https://discourse.julialang.org/t/kwargs-for-getindex-with/18239/5 "2018-12-04T00:26:33Z")

</div>

I thought the kwargs result was a bit odd, but if you can make use of it… =) just watch it isn’t changed / fixed  
It’s dropping the one because it looks like nested code

You might also be able to add a method to Base.typed\_vcat(::Foo)

```julia
f[1;2;3]
> no method matching typed_vcat(::Foo, ::Int, ::Int, ::Int)

Base.typed_vcat(x::Foo, args, kwargs...) = getindex(x, args, nt = kwargs)

f[1; (c=2, d=3)]
> ((1,), Base.Iterators.Pairs(:nt => ((c=2, d=3),) ))
```

---

<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:** [December 4, 2018, 7:10am UTC](https://discourse.julialang.org/t/kwargs-for-getindex-with/18239/6 "2018-12-04T07:10:20Z")

</div>

> [@yuyichao](#):
>
> It doesn’t. It’s simply `2` .

Thanks, I overlooked this.

In any case, I can make the desired syntax work for my use case, which is

```julia
table[(:select, :these, :columns)]
table[drop = (:those, :columns)]

```
