Addressing attributes within a data structure

Many programming languages offer a simple construct to address a single attribute within a data structure (record) e.g.:

Does Snap! support something similarly efficient, easy-to-use, maintainable and self-documenting?

Some non-ideal candidate solutions I considered are:

  • ITEM (name) OF (customer), “name” being a previously initialized constant number;
  • ITEM (name()) OF (customer), “name()” being a function reporting a constant number;
  • ITEM (attribute (person)(name)) OF (customer), “attribute” being a (dual argument) function reporting the order of a specified attribute within a specified data structure)
  • CALL (customer ( )) W/INPUT (name), “customer” being a variable containing a previously initialized (OOP) function.

I wonder if anyone has a better suggestion.

Well, I've added named attributes aka dictionaries to Snap! at the specific request of educators who are teaching data structures:

I should've done a better job documenting this feature, here's a (very) short (and incomplete) introduction: Dictionaries in Snap! v8.1

also, this notation for accessing fields is pretty much the same as the dot-notation in textual languages, don't you agree?

Actually sometime after I had posted my question, but shortly before I read your reply (@jens: thx!) it dawned to me this feature was recently introduced. I agree it resembles other languages’ dot notation.

Thinking aloud a little further: how about data structures with multiple levels? Like:


  1. name
    1.a. first name
    1.b. family name
  2. address ...

Using the same mechanism, e.g. a customer's family name can be addressed as: ITEM (family name) OF (ITEM (name) OF (customer)).

A downside of this mechanism: it only works if field names are included in each of the records, which may involve a lot of redundant memory usage. This, I assume, is due to the fact that Snap! does not explicitly support user-defined data types.