[erlang-questions] Processes memory

Robert Virding rvirding@REDACTED
Fri May 7 15:27:31 CEST 2010


On 7 May 2010 15:00, Marcel Meyer <marcel.meyer@REDACTED> wrote:
> Hi there,
> I have been playing around with the infamous "perms" example where all
> permutations of a word is computed using this code:
>
> perms([]) -> [[]];
> perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])].
>
> ...
> The "processes*" have increased significantly.
> I did not bind the result of that computation, so why is it still consuming
> resources?

The shell keeps a history list of past expressions and values so you
can retrieve the values of previous computations. This even if you do
not explicitly bind the result to a variable. To get around this try
doing something after the perm call but in the same shell expression:

4> test:perm("processese"), 42.

This should calculate the perms but not save them anywhere. You can also do:

5> Ps = test:perm("processese"), 42.

which binds Ps to them but still does not put them on the history list.

> A side note: I posted the perms problem to all our developers in the office
> (a .Net shop), and the fastest version (F#) was still twice as slow as the
> code above.

That is very interesting and gratifying.

Robert

P.S. No Erlang here so I can't test this.


More information about the erlang-questions mailing list