I think that both displayed methods are valid. Similar to tuples, there can be a trailing comma after a non-empty argument list:
julia> abs(-1,)
1
I think that both displayed methods are valid. Similar to tuples, there can be a trailing comma after a non-empty argument list:
julia> abs(-1,)
1
Thanks, I didnât know this. Hmm, I wonder whether this is a feature or an anti-feature. I understand why we have it for tuples and arrays as you might have your elements in separate lines and just want to add another line without caring whether it is the last line.
However, for callables, this only seem to make sense for varargs, which are the exception and not the norm, as otherwise you hardly add or remove some arguments.
Does anyone use this syntax in the REPL and would expect help for the single-argument method after writing the comma?
No I think if youâve typed f('a', and then press TAB itâs reasonable for help to assume you want at least 2 arguments.
Definitely a feature. You want to be able to add and remove lines from calls like this:
foo(
bar,
baz,
)
Lua has the rule that you canât have a trailing comma in function calls and itâs awful.
Besides, as the manual says
Tuples are an abstraction of the arguments of a function â without the function itself.
so it would be weird if their syntax were incompatible.
Thatâs not to say anything about what the REPL help mode should do, I donât have a strong opinion on that.
The reason that the arguments are effectively a Tuple and if it is supported there, it should also be supported for callables, is a strong one.
Could you provide a real-life example for foo where you actually use it? As adding an element changes the method, I would really only expect it to be used for Varargs methods.
Most commonly when there are optional keyword args, which is perhaps less relevant for the help mode discussion (though keyword only-methods do exist). Also when iterating on my own code and signatures change (also less relevant for help mode).