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

Richard Carlsson <>
Sun Feb 22 22:04:38 CET 2009


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?

The benefit is that you don't have to think about implementing
variadic functions, and you still get most of the advantages.
You also get the bonus feature of being able to do slightly (or
even wildly) different things depending on arity...

However, some compiler internals get more complicated since you need
to represent function names as (Name,Arity) pairs; they are not just
identifiers. It isn't difficult to handle, but can be somewhat annoying.

> Were they concisely chosen to help the programmer in some way, were
> they to make implementation easier or more efficient, or did they just
> happen somewhere along the way?

In all likelihood they happened because that is how predicates work
in Prolog, just like most of Erlang's lexical conventions were taken
from Prolog. (The first experiments with Erlang were implemented on
top of Prolog.)

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

No, but Erlang code would have looked different, with many slightly
varying names for standard functions (consider e.g. spawn/3/4), and
probably more functions that take an option list as a final parameter.

    /Richard

-- 
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham



More information about the erlang-questions mailing list