[erlang-questions] arity part of function name and variadic functions

Richard O'Keefe ok@REDACTED
Tue Feb 24 00:31:37 CET 2009

On 23 Feb 2009, at 9:25 am, Peter Michaux wrote:

> I'm reading Joe Armstrong's "Programming Erlang: Software for a
> Concurrent World". Two stand out features of Erlang are
>  1) a function's arity is part of its name and
>  2) there are no variadic functions.
> What are the benefits of these two features from a language design  
> perspective?

(1) One practical merit of this is that it gives you optional
     arguments in a very simple way.  Another is that there isn't
     any need (as there is in Lisp) for run-time code to check that
     the number of arguments is right.  If you arrived at f/N, you
     have N arguments.

(2) What would you want variadic functions for?
     If you want to pass a variable number of items,
     pass a list or a tuple.  If you want *two* groups
     of arguments that vary in number, such as a command
     to send several messages to several processes, just
     pass two lists.  You aren't left wondering which of
     them gets to be the only variable group.

This approach is inherited from Strand88, which inherit it from
Prolog, where it is due to some definitions of logic.

There have been versions of Prolog, notably M-Prolog, where
the module system was based on atoms rather than atom/arity
pairs.  This made it impossible to export f/1 without also
exporting f/2, which was remarkably unpleasant.

I note that in the more conventional functional languages ML,
Haskell, and Clean, every function has the same fixed arity: 1.

> Would the opposite choices have caused bad interaction with the
> process-based concurrency model or some other part of the language?

It's hard to tell what might have been, but probably not.

More information about the erlang-questions mailing list