So now all I'd like in Erlang is...

Chris Pressey cpressey@REDACTED
Fri Feb 20 03:46:15 CET 2004

On Wed, 18 Feb 2004 19:27:03 -0500
Shawn Pearce <spearce@REDACTED> wrote:

> Chris Pressey <cpressey@REDACTED> wrote:
> > How would that work w.r.t. dynamic code reloading?
> I think it would work just like it does now.  The only difference is
> that when a module is loaded, rather than registering its exported
> functions in a table, a module is actually executed.

OK.  There are still some problems with the approach, though.  Mainly -
how do you deal with forward references?

Even self-references in funs currently have to be done like:

  Fact = fun
    (_F, N) when N =< 1 ->
    (F, N) ->
      N * F(N - 1)
  Fact(Fact, 23).

There are at least three ways you could deal with this: you could
adopt Joe's idea for a magical this()-like BIF, or you could do some
equally magical prediction when you see "Fact = fun" and consider Fact
to be bound even within the body of the fun, or you could force the
function to be registered in the export table even if it's solely an
internal utility.

And that's just self-references.  Mutually recursive funs are even more,
uh, fun :)  They can be done, of course, but they're far from pleasant.

I guess what I'm saying is that it *would* be more orthogonal to have
all functions as funs, but even if we did, it probably wouldn't be long
before something like foo() -> bar was introduced as a shorthand for
Foo = fun() -> bar end, register(foo, Foo) anyway.


More information about the erlang-questions mailing list