geometric memory growth

Tony Rogvall tony@REDACTED
Sat Nov 26 17:09:00 CET 2005


> Your point seems to be that the only bindings that should
> occur in
>
>   SendF = fun(To, Msg) ->
>              msg(State#state.channel, ChNo, To, Msg)
>           end
>
> would be State and ChNo - but I'm not interested in State.
> I think it's most intuitive to think of the two
> constructs above as exactly equivalent.

I guess the (not so) general question is something like:

Given a function f and a bound variable B (constant!) . Under what
circumstances may f(B) be evaluated while defining the
function bound to F.

F = fun() ->  f(B) end,

I would guess that any function f not producing side effects would be  
safe to evaluate

	B = {1,2,3},

	F = fun() ->  element(1, B) end,

The expression element(1, B) is of course always constant 1 in the  
above example

While

	B = {1,2,3}

	F = fun() -> self() ! B end,

Is not ok to evaluate while defining F.

One (BIG) problem would be error cases:

g(B) ->
	fun() -> element(1, B) end.

could be rewritten as

g(B) ->
	T1 = element(1, B),
	fun() -> T1 end.

But what if B is not a tuple or is {} then the fault will be  
generated in the wrong place.

While calling g and not when executing function result of g.

(Solution, delay the faults ;-)

/Tony




More information about the erlang-questions mailing list