Returning Name of a Nested Record

Am I correct that there is no way to return the name “set1” from the variable MYDATA below? In other words, if I don’t know the name of that record, I can’t retreive it.

set MYDATA to {set1:{thename:{"default"}, theopen:{"aaa", "bbb", "ccc"}, theclose:{"ddd", "eee", "fff"}}, set2:{thename:{"user name"}, theopen:{"ggg", "hhh", "iii"}, theclose:{"jjj", "kkk", "lll"}}}

Any help is appreciated. Thanks.

Unfortunately, this is correct.

If you did know the names for this record, you could reference it like this:

set MYDATA to {set1:{thename:{"default"}, theopen:{"aaa", "bbb", "ccc"}, theclose:{"ddd", "eee", "fff"}}, set2:{thename:{"user name"}, theopen:{"ggg", "hhh", "iii"}, theclose:{"jjj", "kkk", "lll"}}}
thename of set1 of MYDATA
--> {"default"}

Hi,

If you know the index of the item, then you can cerce to list:


set MYDATA to {set1:{thename:{"default"}, theopen:{"aaa", "bbb", "ccc"}, theclose:{"ddd", "eee", "fff"}}, set2:{thename:{"user name"}, theopen:{"ggg", "hhh", "iii"}, theclose:{"jjj", "kkk", "lll"}}}
item 1 of (MYDATA as list)

gl,

Hi, kel.

I know I shouldn’t get pedantic just before going to bed, but properties of records don’t have indices. The whole point of records is that they’re unordered and that their properties are accessed via labels. That’s why your script has to coerce the record to list “ to get something that is ordered. But there’s no guarantee that the order in the list relates to particular properties in the record. It may often be the case that it does, but it doesn’t have to.

Hi Nigel,

Oh yeah, that’s right. records aren’t ordered. So I guess you should repeat through the list and some item by one of its properties.

set MYDATA to {{thename:{“default”}, theopen:{“aaa”, “bbb”, “ccc”}, theclose:{“ddd”, “eee”, “fff”}}, {thename:{“user name”}, theopen:{“ggg”, “hhh”, “iii”}, theclose:{“jjj”, “kkk”, “lll”}}}

Or, you could just store the sub-records in a list and drop the set part. Now It’s ordered.

Thanks for pointing that out.

Edited: yes, you should drop the record part, because if you don’t know the labels, then it’s no good to you as a record.

gl,