Looping through relations

Very slick, Zed.

The first two versions can be done indirectly with existing functionality:

When play begins:
	repeat with M running through list of numbers that booping relates:
		say "[M]."

When play begins:
	repeat with N running through list of texts to which booping relates:
		say "[N]."

but the third is something new under the sun, and they’re all handy!

The idea can be backported to 6M62 with:

6M62 Backport Phrases
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} = BlkValueRead({-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 (BlkValueRead({-by-reference:r}, {-my:1}) & RRF_USED) {
			if (KOVIsBlockValue({-strong-kind:K}))
				BlkValueCopy({-by-reference:x}, BlkValueRead({-by-reference:r}, {-my:1} + 1));
			else
				{-by-reference:x} =  BlkValueRead({-by-reference:r}, {-my:1} + 1);
			if (1) {-block}
		}
	}
-).

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:
(-
	for ({-my:0} = BlkValueRead({-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 (BlkValueRead({-by-reference:r}, {-my:1}) & RRF_USED) {
			if (KOVIsBlockValue({-strong-kind:K}))
				BlkValueCopy({-by-reference:y}, BlkValueRead({-by-reference:r}, {-my:1} + 2));
			else
				{-by-reference:y} =  BlkValueRead({-by-reference:r}, {-my:1} + 2);
			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} = BlkValueRead({-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 (BlkValueRead({-by-reference:r}, {-my:1}) & RRF_USED) {
			if (KOVIsBlockValue({-strong-kind:K}))
				BlkValueCopy({-by-reference:x}, BlkValueRead({-by-reference:r}, {-my:1} + 1));
			else
				{-by-reference:x} =  BlkValueRead({-by-reference:r}, {-my:1} + 1);
			if (KOVIsBlockValue({-strong-kind:K}))
				BlkValueCopy({-by-reference:y}, BlkValueRead({-by-reference:r}, {-my:1} + 2));
			else
				{-by-reference:y} =  BlkValueRead({-by-reference:r}, {-my:1} + 2);
			if (1) {-block}
		}
	}
-).

I’m not sure that will work in 10.1, but surely something like it can do the trick.

There might be certain bugs to work out for unusual kinds of relations. (I’m not remembering the details, but as I recall the data structures for some of them vary from this format.)

2 Likes