I.e, if I have a record
-record(one, {frag, left}).
- Is
record_info(fields, one)going to always return[frag,?
left] - Is
tl(tuple_to_list(#one{frag = "Frag", left = "Left"}))
always gonna be["Frag", "Left"]?
Is this an implementation detail?
Thanks a lot!
The short answer is: yes, as of this writing it will work. The better answer is: it may not work that way in the future, and the nature of the question concerns me.
It’s safe to use
record_info/2, although relying on the order may be risky and frankly I can’t think of a situation where doing so makes sense which implies that you are solving a problem the wrong way. Can you share more details about what exactly you are trying to accomplish so we can help you choose a better method? It could be that simple pattern matching is all you need.As for the example with
tuple_to_list/1, I’ll quote from “Erlang Programming” by Cesarini and Thompson:There are several good reasons why, including: