Why can't we map tuples on arguments in Rust?

Having this tuple application done automatically and silently is a bad idea. Implicit things that make a language act like that usually bite your ass later. And this pain has happened in other languages.

On the other hand Python uses an application (apply in Lisp lingo) syntax that is both simple, short and explicit:

def foo(a, b):
    print(a)

ab = (1, 2)
foo(*ab)

You can't use a star like that in Rust, but other short syntaxes could be invented.

In D language there are both struct-like library-defined tuples as in Rust, and built-in "type tuples" that can contain argument packs like that. They have a differerent ABI, the type tuples are designed to have the same memory layout as function calls, so they are efficient if you want to apply a tuple as discussed here. In Rust I think such efficiency is missing (if the function is not inlined).

3 Likes