how to extract the number of arguments from a function



On 2012-12-05, JOSE ANTONIO VALLEJO RODRIGUEZ <jvallejo at fciencias.uaslp.mx> wrote:

> foo(x,y,z):= whatever
> and I need some command that tells me the number of arguments 'foo' has (3 in this case).

  length (args (lhs (fundef (foo))));
   => 3

Bear in mind that fundef quotes (does not evaluate) its argument. To
force evaluation of the argument, the standard trick is:

  apply (fundef, [a]);

where a is bound to 'foo or whatever.

Hope this helps,

Robert Dodier