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

Shawn Pearce spearce@REDACTED
Wed Feb 18 01:58:25 CET 2004


Joe Armstrong <joe@REDACTED> wrote:
> I'd really like a do thinks like this ...
> 
> 	% define a module
> 	Mod = {{export,[{foo,2},{bar,1}....]},
> 	       {code, [{foo,2,fun(X,Y) -> ...end},
> 		       {bar,1,fun(X) -> ... end}]}},
> 	% compile it
> 	Code = compile(Mod),
> 	% call code without "publishing it"
> 	Code:foo(1,2)

I've often wondered why Erlang code is:

	foo(X) ->
		ok.

and not:

	Foo = fun(X) ->
		ok
	end.

with call sites using:

	Foo(x).

instead of:

	foo(x).

In other words, why are named functions different from lambdas?  Why
not make all named functions actually global variables which are
assigned to a lambda when the module loads?

As soon as you do this, it becomes possible to do things like:

LoadDetsFile = fun() -> ... pull a dets file into a list .. end.

SomeConstant = LoadDetsFile().

LookupUser = fun(Name) ->
	Lists:Keysearch(Name, 1, SomeConstant)
end.

:-)

> 	There should be multiple versions of old code (not just two)

Yippee!  With this we can get rid of that *killed* message I love
so much when you load the module twice and your servers are plain
Erlang servers which are wedged in a receive call.  :-)

And I can blow up memory footprint by loading modules every few minutes
and never getting the existing processes to switch to the new version.
Oh, that's what I do in Java at work.  :)

This I think is a really good thing.  It removes some risk associated
with code upgrades, and upgrading too quickly.

>   Without any space allocated for processes I'd like the run-time down to
> less than a 500KB - a decent app should be less than 1 Meg.

Wow.  That would be sweet if the runtime could get that small.  I
think only a handful of programs, like say agetty on Linux, run in
that tiny of a heap anymore.

>   Writing C is like performing open brain surgery - it seems easier to
> write programs which write C rather  than writing it myself - that way
> you  only have  to get  the code  generator right  *once*  rather than
> getting every single C program right.

This is why I try to write Java code generators, and not Java code.  I
once did an Erlang code generator in Erlang, and for whatever reason,
found it more painful than I'd like to remember...

I'm all for building a micro-Erlang with no human written C code in it
at all.  :-)

-- 
Shawn.

  Once you've tried to change the world you find it's a whole bunch easier
  to change your mind.



More information about the erlang-questions mailing list