title: How to dynamically build function calls with different numbers of arguments in Rust?
body: <p>How do I take a vector of function argument AST variants, extract the values, and use them to instantiate a function call? </p>
  
  <p>I am writing an interpreter that evaluates certain expressions.  Some of the expressions are function calls.  I am having a hard time figuring out how to translate the function calls AST to the actual call.  The AST gives me the function name and a vector of arguments.  I can lookup the function pointer to call from the name using a map, but passing the arguments to the function pointer is problem. </p>
  
  <p>Rust does not have a splat operator (argument expansion).  I could pass them as a tuple and use destructuring of the arguments, but I can't figure out how to convert the vector of AST argument enum variants to a tuple of the concrete types.  </p>
  
  <p>I can't simply map or loop over the AST arguments to extract the values and produce a tuple.</p>
  
  <p>I can use nested tuples to build a heterogenous list incrementally:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn prepend&lt;I,T&gt;(i: I, t: T) -&gt; (I,T) { (i, t) }
  
  fn foo() {
      let x = ();
      let x = prepend(1, x);
      let x = prepend(2.0, x);
      let x = prepend(true, x);
  }
  </code></pre>
  
  <p>But that only works because <code>x</code> gets shadowed and the new binding has a different type.  This won't work:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn foo() {
      let mut x = ();
      x = prepend(1, x);
      x = prepend(2.0, x);
      x = prepend(true, x);
  }
  </code></pre>
  
  <p>Any ideas?</p>