2021-02-01 10:39:12 +03:00
|
|
|
var samples = [
|
2020-02-19 15:28:29 +03:00
|
|
|
{"a", "b", "c"},
|
|
|
|
|
"string",
|
|
|
|
|
[],
|
|
|
|
|
Fruit ("apple"),
|
2021-02-01 10:39:12 +03:00
|
|
|
fun () {skip}
|
2020-02-19 15:28:29 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
fun show () {
|
|
|
|
|
-- Note: it would be much better to use iterArray from standard unit Array;
|
|
|
|
|
-- in that case, however, we wouldn't be able to showcase
|
|
|
|
|
-- for-loops and []-expressions.
|
2021-02-01 10:39:12 +03:00
|
|
|
for var i; i := 0, i < samples.length, i := i+1 do
|
2020-02-19 15:28:29 +03:00
|
|
|
printf (" %s has %d subvalue(s):\n", samples[i].string, samples[i].length);
|
2021-02-01 10:39:12 +03:00
|
|
|
for var j; j := 0, j < samples[i].length, j := j+1 do
|
2020-02-19 15:28:29 +03:00
|
|
|
printf (" subvalue [%d] = %s\n", j, samples[i][j].string)
|
|
|
|
|
od
|
|
|
|
|
od
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("And now we look at accessing/modifying/analyzing the values.\n");
|
|
|
|
|
printf ("Any composite value can be asked on the number of its immediate subvalues,\n");
|
|
|
|
|
printf ("and these subvalues can be accessed:\n");
|
|
|
|
|
|
|
|
|
|
show ();
|
|
|
|
|
|
|
|
|
|
printf ("And the subvalues of a composite value can be reassigned.\n");
|
|
|
|
|
|
|
|
|
|
samples [2] := [1, 2, 3];
|
|
|
|
|
samples [0][1] := {};
|
|
|
|
|
|
2021-02-01 10:39:12 +03:00
|
|
|
show ()
|
2020-02-19 15:28:29 +03:00
|
|
|
|