more on efene’s structs
I’ve decided that structs are the way to go for efene and removed all traces of “objects” from the code.
The reasons to do this:
- structs are a real data structure and not a closure trick to look like a data structure.
- You can introspect them, operate on them, dump and see what’s inside. This allow people to write code that interact with structs in ways I can’t imagine now. “objects” were hard to modify.
- structs allow nested structs
- friendly syntax to access and modify a struct
- meaningful and simple error messages
- syntax to define structs ad-hoc
- map 1:1 with JSON
- look like JSON
of course if you liked objects they are 100% implemented as a library so you can get the source from some commits ago and use it.
now some code using new functions in the struct module.
>>> Me = {firstname: "mariano", lastname: "guerra", location: {city: "cordoba", country: "argentina"}}
{struct,[{firstname,"mariano"},
{lastname,"guerra"},
{location,{struct,[{city,"cordoba"},{country,"argentina"}]}}]}
>>> struct.fields(Me)
[firstname,lastname,location]
>>> struct.has(Me, firstname)
true
>>> struct.has(Me, email)
false