I’ve wanted this for a long while: a reasonably fast and efficient way to loop through relations.
lab is a room.
foo relates various numbers to various texts.
the verb to boop means the foo relation.
booping is a relation of numbers to texts variable.
booping is initially the foo relation.
4 boops "x".
5 boops "x".
5 boops "z".
6 boops "b".
4 boops "b".
when play begins:
say "Keys (left hand side): ";
repeat for n in keys of booping begin;
say "[n] ";
end repeat;
say ".";
say "Values (right hand side): ";
repeat for t in values of booping begin;
say "[t] ";
end repeat;
say ".";
say "Both!";
repeat for x and y in booping begin;
say "[x] boops [y].";
end repeat;
would yield:
Keys (left hand side): 5 4 5 4 6 .
Values (right hand side): z b x x b .
Both!
5 boops z.
4 boops b.
5 boops x.
4 boops x.
6 boops b.
For the current dev version, what’s expected to be 11.0, sorry. I’ll make an extension later; I just thought I’d share it while it’s hot.
to repeat for/with/-- (y - nonexisting L variable) running/-- through/in values of (r - relation of values of kind K to values of kind L) begin -- end loop: (-
if (PVField({-by-reference:r}, {-my:1}) & RRF_USED) {
if (KindConformsTo_POINTER_VALUE_TY({-strong-kind:L})) BlkValueCopy({-by-reference:y}, PVField({-by-reference:r}, {-my:1} + 2));
else {-by-reference:y} = PVField({-by-reference:r}, {-my:1} + 2);
if (1) {-block}
-)
to repeat for/with/-- (x - nonexisting K variable) running/-- through/in keys of (r - relation of values of kind K to values of kind L) begin -- end loop: (-
for ( {-my:0} = PVField({-by-reference:r}, RRV_STORAGE), {-my:1} = RRV_DATA_BASE + (3 * {-my:0}) : {-my:0} >= 0 : {-my:0}--, {-my:1} = RRV_DATA_BASE + (3 * {-my:0}) ) {
if (PVField({-by-reference:r}, {-my:1}) & RRF_USED) {
if (KindConformsTo_POINTER_VALUE_TY({-strong-kind:K})) BlkValueCopy({-by-reference:x}, PVField({-by-reference:r}, {-my:1} + 1));
else {-by-reference:x} = PVField({-by-reference:r}, {-my:1} + 1);
if (1) {-block}
-)
to repeat for/with/-- (x - nonexisting K variable) and (y - nonexisting L variable) running/-- through/in (r - relation of values of kind K to values of kind L) begin -- end loop: \
(-
for ( {-my:0} = PVField({-by-reference:r}, RRV_STORAGE), {-my:1} = RRV_DATA_BASE + (3 * {-my:0}) : {-my:0} >= 0 : {-my:0}--, {-my:1} = RRV_DATA_BASE + (3 * {-my:0}) ) {
if (PVField({-by-reference:r}, {-my:1}) & RRF_USED) {
if (KindConformsTo_POINTER_VALUE_TY({-strong-kind:K})) BlkValueCopy({-by-reference:x}, PVField({-by-reference:r}, {-my:1} + 1));
else {-by-reference:x} = PVField({-by-reference:r}, {-my:1} + 1);
if (KindConformsTo_POINTER_VALUE_TY({-strong-kind:L})) BlkValueCopy({-by-reference:y}, PVField({-by-reference:r}, {-my:1} + 2));
else {-by-reference:y} = PVField({-by-reference:r}, {-my:1} + 2);
if (1) {-block}
-)
(As you can see, insertion order isn’t preserved.)