AnsweredAssumed Answered

Lists of user-defined types

Question asked by pmlwd@leeds.ac.uk on Jul 25, 2016
Latest reply on Jul 25, 2016 by pmlwd@leeds.ac.uk

Hi there

 

I am trying to use the record structure to store in a single place collections of data of different elementary types. I was hoping to make lists (or perhaps sets) of these records, but my approach doesn't work. Would anyone be able to offer some help, please? I present below some minimalist code that doesn't do what I was hoping for. The idea was to use as a placeholder a one-dimensional version of the record. I would then cycle through various sets of data, populating the record and adding to the list the record as it then existed.

 

     model RecordTester

 

     declarations

          STRINGSET={"STR1","STR2"}

          RECORDTYPE=record

             A:array(STRINGSET) of integer

          end-record

          INDIVIDUAL_RECORD:RECORDTYPE

          LIST_RECORDS:list of RECORDTYPE

     end-declarations

 

          INDIVIDUAL_RECORD.A::(["STR1","STR2"])[1,2]

          writeln(INDIVIDUAL_RECORD)

          LIST_RECORDS+=[INDIVIDUAL_RECORD]

          writeln(LIST_RECORDS,"\n-----")

 

          INDIVIDUAL_RECORD.A::(["STR1","STR2"])[3,4]

          writeln(INDIVIDUAL_RECORD)

          LIST_RECORDS+=[INDIVIDUAL_RECORD]

          writeln(LIST_RECORDS)

     end-model

 

The output I get is as follows:

     [A=[1,2]]

     [[A=[1,2]]]

     -----

     [A=[3,4]]

     [[A=[3,4]],[A=[3,4]]]

 

I think that the list refers directly to INDIVIDUAL_RECORD, rather than having taken its contents: the list contains n copies of the last-added entry, where n is the number of loops. Is what I tried to do possible for non-basic entries, such as my record? One way around this would be to have not a placeholder, but an array of records, with the list referring to its various elements.

 

Any help that can be offered on this or other approaches would be greatly appreciated.

Outcomes