# Allowing the object.method(args...) syntax as an alias for method(object, args ...)

**URL:** <https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051>\
**Category:** Internals & Design\
**Tags:** question, design\
**Created:** [May 29, 2021, 5:09pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051 "2021-05-29T17:09:54Z")\
**Posts on this page:** 20\
**Page:** 7

<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:** [October 5, 2022, 5:33pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/128 "2022-10-05T17:33:38Z")

</div>

> [@jling](#):
>
> But I guess you’re echoing OP’s proposal

Um, no, not in a million years. I just saying maybe some _convenient_ shortcut, other than `|>`, to trigger function completion could be an idea.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 5, 2022, 5:42pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/129 "2022-10-05T17:42:54Z")

</div>

idk, you need some indication of you’re trying to look for a function, so it’s either `|>`, or

```julia
[cursor](obj) # hit tab

```

---

<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:** [October 5, 2022, 6:18pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/130 "2022-10-05T18:18:02Z")

</div>

I’m thinking `obj[cursor]`, then pressing `<alt-space>` for example, maybe user configurable. Are there mechanisms for triggering this kind of user-configurable actions in vs code or the REPL?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 5, 2022, 6:19pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/131 "2022-10-05T18:19:43Z")

</div>

too confusing… that’s some mental burden I don’t want users to suffer from. can do in a package for sure

---

<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:** [October 5, 2022, 6:23pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/132 "2022-10-05T18:23:17Z")

</div>

Huh? I don’t even understand what you mean. How would this affect anyone who’s not directly interested in the functionality?

No-one needs to use this, and user-configurable shortcuts aren’t anything new. It just needs some action to hook up to.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 5, 2022, 6:30pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/133 "2022-10-05T18:30:06Z")

</div>

it’s a mental burden to make user to remember “oh tab in completion in Julia but if you want to complete function you can’t just do it like 10 other language, you need to hit this specific combo of keys that literally has no other usage”

unlike `|>`, there’s absolutely no que for why `alt-space` is needed(and not, ctrl-tab?), at least `|>` is a pipe operation which is common and it tells julia you’re competing for function, which users can make sense of

if you only use julia and use it all the time, you might as well just remember all the functions you ever need…

---

<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:** [October 5, 2022, 7:08pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/134 "2022-10-05T19:08:40Z")

</div>

> [@jling](#):
>
> it’s a mental burden to make user to remember “oh tab in completion in Julia but if you want to complete function you can’t just do it like 10 other language, you need to hit this specific combo of keys that literally has no other usage”

I think you are completely missing my point. If this is configurable, anyone could trigger completion whichever way they prefer. `|>` could very well be the default, and only those who care would go to whatever config-file to change it.

BTW, alt-space is a common way to trigger completion (e.g. intellij et al) which is why I thought of that first.

One more thing: `obj |> <tab>` should probably complete to `obj |> foo`, not `foo(obj)`, which means the latter should be triggered differently.

> [@jling](#):
>
> if you only use julia and use it all the time, you might as well just remember all the functions you ever need…

Just because you remember them doesn’t mean you want to _type_ them out fully.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [October 5, 2022, 9:28pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/135 "2022-10-05T21:28:38Z")

</div>

I think tab is more common than alt-space? Its tab in R studio, VS code, and very common with plugins in vim.

And tab already does completion in the Julia REPL, it’s just for everything in the namespace rather than everything that could actually be parsed and run. Reducing the length of that list in specific contexts is the improvement I’m suggesting we make.

> One more thing: `obj |> <tab>` should probably complete to `obj |> foo`, not `foo(obj)`, which means the latter should be triggered differently.

I agree, `|>` should end up as a pipe. See my post above, we could hit tab after a bracket to complete `foo(obj)` if it was just written like a tuple/paren `(obj)`.

---

<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:** [October 5, 2022, 10:00pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/136 "2022-10-05T22:00:40Z")

</div>

> [@Raf](#):
>
> I think tab is more common than alt-space?

Yes, _maybe_, but I’m mentioning this only because it would be useful to configure this according to one’s own preference.

For me, the problem with `<tab>` for this specific use is ambiguity. If I type `obj<tab>`, the natural choice is to complete the name `obj`, not look for applicable functions. `obj.<tab>` should complete property names. `obj |> <tab>` is awkward to type, and so is `(obj)<tab>`.

`obj<alt-space>` is just handy and widespread for this use, so I thought that is what I, _personally_, would like to configure as a trigger that deliberately acts differently from `<tab>`.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [October 5, 2022, 11:40pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/137 "2022-10-05T23:40:35Z")

</div>

Ok I get it, you would like a solution that is independent of syntax and just operates directly on the object.

That seems useful and yes it would need a separate key command.

So `<alt-space>` (or whatever) could complete `obj` to `func(obj)` or `func(obj, _)` or `func(_, obj)` depending on method arguments? then you could be in some kind of function mode where tab takes you to fill in the next argument if there are multiple. It could force mandatory keywords as well. I can see it getting tricky when there are a lot of method signatures.

(a reason to keep personal likes out of this and choose the “one right way” is now we would have to implement all these things…)

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [October 6, 2022, 4:57am UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/138 "2022-10-06T04:57:51Z")

</div>

I’ll take this moment to draw your attention to @DNF’s complaints that `|>` is awkward and error-prone to type, and `?(obj)<tab>` is strange. My commentary as well.

Might I interest you fine folks in `..`, such as in `my_object..mymethod()`? Methods would appear in a dropdown menu as you type them, sorted by relevance, and you’d hit \<tab\> to complete the suggestion. Thing of beauty. Much wow.

Okay, so _inserting the object as a first argument_ is still getting pushback. I’d argue this isn’t as big a deal as it’s being made out to be, and that it simply can’t be expected that all functions will be written with argument ordering that makes good use of it. But in the contexts where it matters, _most_ methods are written with reasonable argument ordering, and the existence of a handful of poor method definitions isn’t compelling motivation to throw babies out with bathwater.

Inserting the object as a first argument, UFCS-style, seems quite reasonable. And virtually the entire world of people who write programs for a living seems to agree.

---

<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:** [October 6, 2022, 7:35am UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/139 "2022-10-06T07:35:47Z")

</div>

> [@uniment](#):
>
> And virtually the entire world of people who write programs for a living seems to agree.

You presumably mean the entire world of people who use and prefer OOP languages? 😛

Anyway, my main point is that I would wish for the functionality and the triggering mechanism to be orthogonal concerns.

I am, BTWm wondering about the implementation of the interface. Looking at the ipython console, which runs in my terminal, `<tab>`bing brings up an interface like the below, where I can navigate with arrows keys in a popup pane, and select the alternative I like.

![image](https://global.discourse-cdn.com/julialang/original/3X/d/a/da0a6964dea90f7470fa4acf278a72e69d54d1a6.png)

Trying the same in the Julia REPL, `<tab>`bing twice just prints out the alternatives, no navigation:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/a/5a7463604f041550aac5f9c4d8e1e8ca3ff8d49b.png)

Is the ipython behaviour something that is possible to implement in the Julia REPL, or are there deeper architectural reasons why the Julia REPL apparently does not offer any such interface. I’ve seen some cool things, like [TerminalMenus.jl](https://github.com/nick-paul/TerminalMenus.jl), and [Term.jl](https://github.com/FedeClaudi/Term.jl), and [FoldingTrees.jl](https://github.com/JuliaCollections/FoldingTrees.jl), and but nothing like the ‘popup-pane’ of ipython.

Maybe TerminalMenus.jl could be an interface, with some background coloring etc.?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 6, 2022, 9:36am UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/140 "2022-10-06T09:36:43Z")

</div>

In terms of interface, [GitHub - tkf/InteractiveCodeSearch.jl: Interactively search Julia code from terminal](https://github.com/tkf/InteractiveCodeSearch.jl) might be a decent option, but I don’t know how that’s implemented under the hood.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [October 6, 2022, 9:47am UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/141 "2022-10-06T09:47:23Z")

</div>

There’s no reason we couldn’t have that. See e.g.

> <https://github.com/JuliaLang/julia/pull/43838>
>
> This is a proposal to introduce a fish/ipython-like completion feature to Julia'…s REPL. The current completion is not complete as it cannot select one from completion candidates. With this change, you can select one just by hitting the tab key several times. The following screencast demonstrates the behavior of proposed tab completion and navigation with arrow keys after \`fi\[Tab\]\`.
> !\[Screen Recording 2022-01-17 at 17 22 45\](https://user-images.githubusercontent.com/905683/149734803-483f8e10-8b7c-4460-bd0e-5c86f89e862e.gif)
> 
> This pull request is just a crude draft to demonstrate my proposal. If you like the idea, I'm happy to polish the code to review.
> 
> \---
> 
> \- Conceptually, it introduces "completion mode" to the ordinary prompt. In completion mode,
> - Completion candidates are displayed as a table below the input.
> - Keybindings are changed so that you can select a candidate with tab, shift+tab, ctrl+n/p, and arrow keys.
> - A selected candidate is highlighted.
> - Any other keys make the prompt exit from completion mode (perhaps, narrowing candidates may be more useful).
> \- When you hit a tab key in edit mode with a partial string, one of three completions will happen:
> 1. if there is one and only one completion candidate, the partial string is extended to it.
> 2. if there are two or more candidates, the partial string is expanded to the common prefix of these candidates and the prompt enters completion mode (nothing is selected at this moment).
> 3. if \`sum(\[tab\]\` (say), a list of methods is displayed (technically, this is not a completion).
> 
> \---
> 
> TODO
> \- \[x\] Pagination
> \- \[x\] Method listing
> \- \[\] Keybinding improvement
> \- \[\] Fallback for poor terminal emulators
> \- \[\] Documentation
> \- \[\] Test

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [October 6, 2022, 10:04am UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/142 "2022-10-06T10:04:15Z")

</div>

Your idea is adding new syntax to the language, my idea is simply a plugin for the REPL that works with the status quo.

The problem being your idea is much less likely to be merged no matter what people think of it in this thread.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 6, 2022, 6:25pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/143 "2022-10-06T18:25:55Z")

</div>

> [@uniment](#):
>
> Might I interest you fine folks in `..`, such as in `my_object..mymethod()`? Methods would appear in a dropdown menu as you type them, sorted by relevance, and you’d hit to complete the suggestion. Thing of beauty. Much wow.

This can’t and won’t work without a breaking change to the parser, since `..` already exists as a function, and binds less tightly than function calls:

```julia
julia> Meta.@dump my_object..mymethod()
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol ..
    2: Symbol my_object
    3: Expr
      head: Symbol call
      args: Array{Any}((1,))
        1: Symbol mymethod

```

that is, this get’s parsed as `my_object..(my_method())` instead of `(my_object..my_method)()`

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [October 6, 2022, 6:38pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/144 "2022-10-06T18:38:22Z")

</div>

Indeed, naturally I’ve tried:

```julia
..(obj, meth) = (args...; kwargs...) -> meth(obj, args...; kwargs...)

```

And it works, sorta, except the expression ends up requiring extra parentheses:

```julia
(my_object..mymethod)(a, b, c)

```

which gets very awkward when chaining. Also broadcasting doesn’t work.

Anyway, is it worth defending `..` from breaking changes? Is there a way to find out if anyone uses it?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 6, 2022, 6:47pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/145 "2022-10-06T18:47:44Z")

</div>

> [@uniment](#):
>
> Anyway, is it worth defending `..` from breaking changes? Is there a way to find out if anyone uses it?

Nobody is going to break compatability just to make people used to class based OO happy. It’s just not going to happen.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [October 6, 2022, 10:32pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/146 "2022-10-06T22:32:35Z")

</div>

> [@uniment](#):
>
> Is there a way to find out if anyone uses it?

[Intervals.jl](https://invenia.github.io/Intervals.jl/latest/) is [fairly popular](https://juliahub.com/ui/Packages/Intervals/ihXRn/1.8.0?page=2).

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [October 6, 2022, 11:58pm UTC](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051/147 "2022-10-06T23:58:38Z")

</div>

Why on earth is this thread still going on about major version-breaking `..` changes or piping that is restricted to single-argument functions when CBOOCall.jl was already suggested in that comment? I don’t like making function names properties of a type in a non-OOP language (which is also why I consider this worse than simply inputting the first argument unusually like do-blocks), but if you’re going to do it, that looks like the way to do it. Only thing I don’t like about that package is that I still can’t tell what CBOO stands for.

[Previous page](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051.md?page=6)

[Next page](https://discourse.julialang.org/t/allowing-the-object-method-args-syntax-as-an-alias-for-method-object-args/62051.md?page=8)
