[erlang-questions] Arrays and setelement

Joel Reymont <>
Sat Jan 6 23:49:13 CET 2007


Bjorn,

What is the reason behind the literal index restriction?

Why not allow the optimization if J was assured by a 'when' guard to  
be, say, an integer.

	Thanks, Joel

On Jan 4, 2007, at 4:02 PM, Bjorn Gustavsson wrote:

> Furthermore, the first argument for setelement/3 (the Index argument)
> must be a literal index for the optimization to place.
>
> Therefore, the second call to setelement/3 will be replaced with the
> cheaper "destructive setelement instruction" in this code
>
> set(T0) ->
>     T = setelement(3, T0, a),
>     setelement(2, T, b).
>
> but not in this code
>
> set(I, J, T0) ->
>     T = setelement(I, T0, a),
>     setelement(J, T, b).

--
http://wagerlabs.com/








More information about the erlang-questions mailing list