I’m just wondering what would be the best choice to model a domain-specific concept. If I take as an example the concept of a pet, with a name and a size. I see two options:
The first option allows me to use the Head aPet in my patterns. But it seems to me that the extraction of raw data is more verbose:
lotOfPets = {aPet["name"->"name1","size"->size1], aPet["name"->"name2","size"->size2],...};
lotOfPets /. aPet[___,"size" -> size_Integer, ___] -> size;
(* OR *)
Last/@Last/@lotOfPets (* I don't like this one because it is tightly linked to fixed positions in the expression*)
The second option allows me to more easily extract data using ReplaceAll:
Right. But my question was more about the best choice in a modeling process between a built-in data structure with all its advantages (like the practical way to query a Dataset or the easy way to extract the elements of a List with ReplaceAll) and a user-defined data structure (an expression with a user-defined Head). Then I remembered these Upvalues and Downvalues allowing you to setup operations linked to your Head. For example the cross between two pets with the operator +: