Structs (was RE: Record selectors)
Vlad Dumitrescu (EAW)
Vlad.Dumitrescu@REDACTED
Tue Jan 14 12:14:15 CET 2003
I have to say: wow Joe, great! This I haven't thought about!
I'll throw in some wild ideas that might (if they can be made to work) to alleviate some of the disadvantages of structs and/or to ease the transition from records.
* Add a mk_static_struct(Name, Fields) function that will make the struct be implemented just like a record and will disallow the add/delete key features. This could be used when efficiency is more important than flexibility.
* Modify the -record() directive to create a static struct instead. This will enable the same kind of consistency between modules as today. Not the best solution, but an acceptable first step, I think.
* I still feel that turning somehow a struct/record/utype into a module describing & implementing it, would be a good idea. Or at least not a bad one :-)
One reason would be that this would make default values for structs possible by defining a set of keys to be included at creation time.
Another reason would be that by using packages, one might solve the problem with the same record name in different hrl files - and discovering one needs to include both in the same module...
The possible drawback is efficiency, but if the compiler can optimize most things, then that might not be a big problem.
best regards,
Vlad
More information about the erlang-questions
mailing list