geometric memory growth

Ulf Wiger ulf@REDACTED
Sat Nov 26 12:22:36 CET 2005


Den 2005-11-25 13:17:31 skrev Thomas Lindgren <thomasl_erlang@REDACTED>:
>
> --- Ulf Wiger <ulf@REDACTED> wrote:
>
>> The obvious fix:
>>
>>     Channel = State#state.channel,
>>     SendF = fun(To, Msg) ->
>> 	          msg(Channel,
>> 	          ChNo, To, Msg)
>> 	      end,
>>
>> Now, wouldn't it be great if the compiler could
>> figure out how to do this
>> at compile-time?
>
> Hoisting the expression out of the fun is only safe if
> State is known to be a #state record at this point.
> Otherwise, you can get an exception in the wrong
> place.

Forgive me, but I can't help thinking that an exception
when the fun is applied would be the wrong place, rather
than when the fun is instantiated. The fun's environment
is bound when it the fun is bound, so I think it would
be intuitive to get the exception at the binding
occurrence rather than later. After all, the record field
access can have no side effects (apart from the run-time
error when accessing the field of a non-record), and
semantically, the access _has_ to be done at the binding
occurrence - if it is delayed, one has to lug the entire
record along to make sure that the record field access
has the same result as it would have had at the binding
occurrence.

You said there are corner cases. I'd like to hear about
them. I would say that it isn't obvious either from the
erlang 4.7 specification or the erlang reference manual
what exactly is supposed to happen.

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.

/Uffe
-- 
Ulf Wiger



More information about the erlang-questions mailing list