Doubt about funs

Chris Pressey cpressey@REDACTED
Wed Feb 21 20:59:11 CET 2001

"Erik.Johansson" wrote:
> Paulo Ferreira  wrote:
> > So, here is another advantage of erlang: One doubt and in two hours time
> > I have five correct answers !!!
> And then the obligatory debate starts ;)

Can a lowly newbie like myself get in on this action? :-)

>  To summarize my view:
>  1. For short lived tasks: always use a fun.
>  2. For spawing use a tail-recursive fun.
>  3. For long-lived (call-backs) either make a careful design or stick to {M., F} if you feel that it is easier.

Earlier, Martin Bjorklund wrote:
> Just to make my point clear, I do like funs, and I use them all the
> time, but only for short-lived tasks like in a local lists:foreach
> etc.  In code that e.g. registers callbacks to be invoked at a later
> time, I use the tuple syntax.

To me, "short-lived" has little to do with it...

As I understand it - fun objects were introduced into Erlang so that
functions passed to and returned from other functions could be anonymous
(and so they could "lift" closure variables, which obviously cannot be
done inside named functions).

So when I go to write a function I generally ask myself - is it a
rendez-vous point - does it deserve a name?  If it's going to be
referred to elsewhere, it will need one.  If not, it's local and should
probably be a fun.

Here's the interesting question, though.  How would one go about making
a tail-recursive (anonymous) fun anyway?  It can't call itself, because
it doesn't have a name  :-)


"Ten short days ago all I could look forward to was a dead-end job as a
engineer.  Now I have a promising future and make really big Zorkmids."
Chris Pressey, Cat's Eye Technologies,
Esoteric Topics Mailing List:

More information about the erlang-questions mailing list