This might be a naive question, and I suspect the answer is yes, but Iβm not lucky to find terms like erlang compiler optimization constants here and elsewhere, etc.
Anyway, can the erlang compiler (will) create a data structure that is constant or literal at compile time, and use this instead of creating code that creates the data structure again and again? I will give a simple example of the game.
test() -> sets:from_list([usd, eur, yen, nzd, peso]).
Maybe (will) the compiler just insert the set there at the output of the function, and not calculate it every time?
I ask if I want to have a lookup table in the program that I am developing. A table is simply constants that can be calculated (at least theoretically) at compile time. I would just like to compute a table once, and don't need to compute it every time. I know that I can do this in other ways, for example, to compute a thing and save it in a process dictionary, for example (or, possibly, an ets or mnesia table). But I always start simple, and for me the simplest solution is to do it as an example of the toy above, if the compiler optimizes it.
If this does not work, is there any other way to achieve what I want? (I think I could look at parsing conversions if they work for this, but is it getting more complicated than I would like?)
IT'S SIMPLE. I used compile: file / 2 with the 'S' option to create the following. I'm not an erlang installation expert, but it seems like optimization is not being performed:
{function, test, 0, 5}. {label,4}. {func_info,{atom,exchange},{atom,test},0}. {label,5}. {move,{literal,[usd,eur,yen,nzd,peso]},{x,0}}. {call_ext_only,1,{extfunc,sets,from_list,1}}.