[erlang-questions] pass-by-reference...

Richard Carlsson <>
Sun Apr 15 18:52:48 CEST 2007


tsuraan wrote:
> According to the book Programming Erlang (I'm pretty sure, although I 
> can't find the reference anymore), function arguments are always 
> pass-by-value unless they're binary types.  Only binaries are pass by 
> reference.  Why is this?  Erlang is purely functional, so it seems that 
> passing a reference to a list of ten thousand integers would be 
> perfectly safe, and much more efficient than copying the list and then 
> calling the function with the copied data.  Is there some danger in 
> giving references to data rather than making copies?

You must have misunderstood something. (Possibly, what you were reading
was a discussion about message passing between processes on the same
node - in that case, binaries are handled specially, in the standard
runtime system.)

Rest assured that for function calls, each argument is passed as a
single word only: either a pointer, or an "immediate" value (e.g.,
atoms, and integers smaller than about 28 bits - or about 60 bits
on a 64-bit machine). Erlang doesn't even have a built-in "clone"
function, since there is no need for it: there are no destructive
update operations.

     /Richard



More information about the erlang-questions mailing list