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

Peter Michaux petermichaux@REDACTED
Wed Feb 25 03:23:39 CET 2009


Thanks to everyone who replied.

On Mon, Feb 23, 2009 at 3:31 PM, Richard O'Keefe <ok@REDACTED> wrote:

> (2) What would you want variadic functions for?

There are many examples in lisp. Sum is a variadic function so that
summing two or more items have the same syntax. If there were no
variadics and it was desirable to have the same syntax for summing two
or more items, then summing two would need to be written in quite a
bulky fashion (+ (list a b))

Functions like map are also variadic in lisp. The common case has
simple syntax (map f a) and then extends naturally to the less common
case of multiple lists (map f a b c)

I'm not here to argue in favor of how lisp does it. This is simply a
possible answer to your question.

>    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.

Good point.

Thanks again,
Peter



More information about the erlang-questions mailing list