Function discovery

Today I wrote my first program in Julia (solution for Advent of Code 15)!

A problem I immediately hit is function discovery. E.g. if have an object x, what can I do with it? In many other languages I type x. and the IDE helpfully autocompletes the list of things I can do with it. Not so in Julia (I’m using VS Code with the Julia plugin btw).

Perhaps Julia could benefit from some syntax sugar similar to Rust, where x.f(args..) is equivalent to f(x, args...)?

Alternatively, if |> did currying, then x |> f(args...) could trigger the autocompletion instead. What do you think?

1 Like

This has been discussed many times!

See:

We cant just use x.f like that because the syntax is already taken - there can already be an object or a function field at x.f.

The Julia alternative is methodswith(typeof(x)). It will give you methods that match args at any position.

Yes, its kind of a pain compared to OOP tab completion, one of the very few downsides of using multiple dispatch.

4 Likes

That’s nice, even if it’s only useful in interpreter mode!

From the threads that you’ve linked I’ve also discovered ?("hello") introduced in ?(x, y)TAB completes methods accepting x, y by timholy · Pull Request #38791 · JuliaLang/julia · GitHub, though that doesn’t seem to be integrated in the VS Code plugin.

Rust also does multiple dispatch, even more powerful than Julia because it also dispatches on the return type. Uniform Call Syntax is still very useful in that scenario.

Still, there seems to be enough opposition to UCS that I guess it won’t get adopted in Julia. This is a bit surprising given Julia already has sugar for treating the first argument specially when it’s a function (do ... end), so it’s not like the language is completely opposed to useful sugar.

Guess I’ll wait until editor plugins adopt ?("hello") autocompletion or until the |> currying comes along.

1 Like

Rust doesn’t have dynamic multiple dispatch or functions being constantly added at run-time, so the problem is simpler.

If you want editor plugins to adopt something quickly, the best strategy may be to make a PR :wink: