Doubt about funs

Richard Carlsson <>
Wed Feb 21 14:09:05 CET 2001


On Wed, 21 Feb 2001, Martin Bjorklund wrote:

> Ulf Wiger <> wrote:
> 
> > Since funs are actually made into real functions by the compiler, they
> > seem to have roughly the same properties as ordinary functions during
> > code change. I've run some tests, and it does seem to be the case that
> > as long as the fun is tail recursive (doesn't wait for a return
> > value), then upgrading doesn't break the fun as long as the arity
> > stays the same. This is the same as for ordinary functions.
> 
> erik> What you describe will happen in the current implementation if
> erik> the function defining F is changed (or any funs are added or
> erik> removed before the fun defining F). 

Never depend on funs "migrating" from old code to new, even if you did not
add or remove funs from the code (i.e., even if the internal fun-indexing
inside the module stays the same over the code change). The code executed
by a fun should be exactly that in the version of the module used to
create the fun-value. Coming Erlang implementations will assure this by
using a module-checksum to identify the correct code for a fun, or crash
the call if that version has been purged. (In the current implementation a
fun could only survive at most one code change anyway, so it was not
really much of a help. The new scheme is more consistent.)

	/Richard

Richard Carlsson ()   (This space intentionally left blank.)
E-mail: 	WWW: http://www.csd.uu.se/~richardc/




More information about the erlang-questions mailing list