3 ms·
Your record–array correspondence reminded me of Nils Holmes's T3X language: it has "struct" defintions like this: STRUCT struct_name = field_1, ..., field_
by Joker_vD 4y ago
Your record–array correspondence reminded me of Nils Holmes's T3X language: it has "struct" defintions like this:
STRUCT struct_name = field_1, ..., field_N;
but it's just a syntactic sugar for
CONST field_1 = 0, ..., field_N = N-1, struct_name = N;
just so that suitably sized vectors can be used as records:
STRUCT POINT = PX, PY, PCOLOR; ! same as CONST PX = 0, PY = 1, PCOLOR = 2, POINT = 3;
VAR p[POINT]; ! same as VAR p[3];
p[PCOLOR] := 42; ! same as p[2] := 42;
It works reasonably well and actually allows for somewhat better meta-programming than e.g. C with its X-macros because you can literally loop over a struct's field, in a normal FOR loop.
- vore 4y agoIt seems like this only works with dynamic typing or if you assumed every field was the same width? Otherwise you can't actually specify the widths of each of the struct fields.
- cmrdporcupine 4y agoI'd think the compiler and language runtime could know the width for any particular offset at access time.