geometric memory growth
Ulf Wiger
<>
Sun Nov 27 00:10:29 CET 2005
Den 2005-11-26 17:09:00 skrev Tony Rogvall <>:
> 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,
Isn't this basically an example of constant propagation?
As in when:
X = 17,
Y = X + 2.
then the compiler would be safe to optimize away
the arithmetic and simply convert to:
X = 17,
Y = 19.
So record field selection could only be a case of
constant propagation if we _know_ that the variable
used for the record is in fact of the right type.
Fair enough.
>
> 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 faultwill be generated in
> the wrong place.
Yes, and this would be analogous if we maintain that
record field selection is just syntactic sugar for
element/2... ok, it _is_ analogous, since that's exactly
the case today, but only because the compiler throws
away essential information. This leads to other
problems, as pointed out elsewhere.
If we think that it's supposed to behave as it does today,
I believe there should be some text in the documentation
explaining the finer points of the record syntax. (:
/Uffe
--
Ulf Wiger
More information about the erlang-questions
mailing list