Hi,
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:
createPet[name_String, size_Real] := aPet["name"->name,"size"->size];
or
createPet[name_String, size_Real] := {"name"->name,"size"->size};
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:
lotOfPets = {{"name"->"name1","size"->size1},{"name"->"name2","size"->size2},...};
Flatten["size"/.lotOfPets]
What do you think?
Best
Fabrice