To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE/YASS documentationRecord structure data type

ZPE officially added in the record data type in ZPE 1.10.5 on April 23rd 2022, and have been supported since Fantastic Fox (May 2022).

Prior implementations were always buggy, didn't make sense, had horrid syntax, or were too similar to other constructs such as the map or object.

The record data structure is officially known as the record structure, and it's use case is similar to that of structures or objects.

Inspiration for the design of the record structure came from the C-style of doing things, but I feel it's better suited to this. As a teacher in Scotland, it was also the best way to do it in relation to the SQA's way of doing it.

Since they are similar to structures, I decided the best syntax for defining them involved both the record and the structure keywords:

YASS
record structure pupil {
  string forename = "Jamie",
  string surname = "Balfour"
}
  

It should be noted that the values in a structure cannot be left unspecified, but in a record structure they can be left with no value at all.

YASS
record structure pupil {
  string forename,
  string surname
}
  

Using record structures

Record structures, much like structures, are instantiated before their use. This is done with the two keywords, the new create keyword (added in version 1.10.5) and the record keyword. Since it is an instance of a record structure, it is created and the new keyword was still reserved for working with objects and structures.

YASS
$pupil1 = create pupil record
$pupil2 = create new pupil record
  

Record structures also must be usable in the program. By default record structures provide the standard accessor (get) and setter (set) methods to manipulate a record instance, each automatically tailored to what fields are defined in the record.

YASS
$pupil1.forename("John")
$name = $pupil1.forename()
  

Here is an example of a program that reads in a CSV file, decodes it and then transforms it in to a bunch of records:

YASS
record structure pupil {
  string forename,
  string surname
}

$pupils = []
$pupil_data = csv_decode(file_get_contents("pupils.csv"))
for each($pupil_data as $pupil)
  $p = create pupil record
  $p.forename($pupil[0])
  $p.surname($pupil[1])

  list_add_element(&$pupils, $p)
end for

  
Comments

There are no comments on this page.

New comment
Reply
Code previewClose
Feedback 👍
Comments are sent via email to me.