List order reversed (uses bach)

lordcacops's icon

Hello, I hope you are doing well.

I am working on a patch and I have been dealing with a problem for a while now. I abstracted the problematic part to post here. The fact that it uses the bach library is probably relevant.

I have a system intended to backtrack through a list of fractions backwards, by increasing with a counter the amount that is to be subtracted from the address (index), so that if it receives address 4, it should retrieve address 3, 2, 1, and stop at 0. The address and the list are received by a bach.nth object, which retrieves the list item at the given address.

Now, if the system worked correctly, starting with index 4, it should retrieve the elements from the list [1/8 1/4 1/4 1/4] in the following order: 1/4, 1/4, 1/8; that is, the values for addresses 3, 2, and 1. Instead, via the system of automatic iteration, it retrieves the values in the order 1/8, 1/4, 1/4; in other words, backwards.

Do you perhaps know what the problem may be? If I do the iteration manually, one by one, the thing works. But in the way I'm doing it now, the list arrives backwards, as can be seen in the [prepend append] object that collects the fractions into a list.

Below is the patcher. I marked the steps, that is, what to press (the address: 4, and the list) with numbers, to specify the order in which they should be pressed.

Thank you.

{
	"boxes" : [ 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "2)",
				"numinlets" : 1,
				"id" : "obj-20",
				"fontsize" : 16.0,
				"numoutlets" : 0,
				"patching_rect" : [ 98.0, 25.999999165534973, 78.0, 24.0 ],
				"fontface" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "1)",
				"numinlets" : 1,
				"id" : "obj-18",
				"fontsize" : 16.0,
				"numoutlets" : 0,
				"patching_rect" : [ 266.5, 25.999999165534973, 78.0, 24.0 ],
				"fontface" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "RESET",
				"numinlets" : 1,
				"id" : "obj-15",
				"numoutlets" : 0,
				"patching_rect" : [ 109.0, 301.0, 56.0, 20.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "4",
				"numinlets" : 2,
				"id" : "obj-13",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 300.0, 25.999999165534973, 29.5, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "+ 1",
				"numinlets" : 2,
				"id" : "obj-9",
				"numoutlets" : 1,
				"outlettype" : [ "int" ],
				"patching_rect" : [ 386.0, 168.0, 29.5, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "button",
				"numinlets" : 1,
				"id" : "obj-11",
				"parameter_enable" : 0,
				"numoutlets" : 1,
				"outlettype" : [ "bang" ],
				"patching_rect" : [ 266.5, 159.0, 24.0, 24.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "fraction to float",
				"numinlets" : 1,
				"id" : "obj-50",
				"numoutlets" : 0,
				"patching_rect" : [ 222.8333340883255, 491.535714566707611, 99.333331823348999, 20.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "t b l",
				"numinlets" : 1,
				"id" : "obj-43",
				"numoutlets" : 2,
				"outlettype" : [ "bang", "" ],
				"patching_rect" : [ 211.0, 185.0, 29.5, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "set $1",
				"numinlets" : 2,
				"id" : "obj-37",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 252.0, 126.0, 41.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "f 0.",
				"numinlets" : 2,
				"id" : "obj-8",
				"numoutlets" : 1,
				"outlettype" : [ "float" ],
				"patching_rect" : [ 466.25, 521.0, 29.5, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "/ 0.",
				"numinlets" : 2,
				"id" : "obj-137",
				"numoutlets" : 1,
				"outlettype" : [ "float" ],
				"patching_rect" : [ 318.75, 551.381997227668762, 29.5, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "zl.slice 1",
				"numinlets" : 2,
				"id" : "obj-132",
				"numoutlets" : 2,
				"outlettype" : [ "", "" ],
				"patching_rect" : [ 318.75, 509.86340969369121, 55.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "fromsymbol @separator /",
				"numinlets" : 1,
				"id" : "obj-130",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 318.75, 467.535714566707611, 143.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "null 1/8 1/4 1/4",
				"linecount" : 2,
				"numinlets" : 2,
				"id" : "obj-90",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 26.464404874130196, 731.32870751619339, 53.0, 35.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "prepend append",
				"numinlets" : 1,
				"id" : "obj-91",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 26.464404874130196, 700.32870751619339, 96.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "1/8 1/4 1/4 1/4",
				"numinlets" : 2,
				"id" : "obj-4",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 137.5, 25.999999165534973, 119.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "i 1",
				"numinlets" : 2,
				"id" : "obj-47",
				"numoutlets" : 1,
				"outlettype" : [ "int" ],
				"patching_rect" : [ 343.999998807907104, 111.769229352474213, 29.5, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "0 1 2 3 0",
				"linecount" : 2,
				"numinlets" : 2,
				"id" : "obj-121",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 653.323171138763428, 178.5, 43.788995265960693, 35.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "prepend append",
				"numinlets" : 1,
				"id" : "obj-122",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 653.323171138763428, 137.0, 96.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "3 2 1 0",
				"numinlets" : 2,
				"id" : "obj-75",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 444.229877591133118, 335.0, 53.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "prepend append",
				"numinlets" : 1,
				"id" : "obj-76",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 444.229877591133118, 258.36905425786972, 96.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "expr $f1 - $i2",
				"numinlets" : 2,
				"id" : "obj-80",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 444.229877591133118, 726.484255492687225, 79.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "t b f",
				"numinlets" : 1,
				"id" : "obj-45",
				"numoutlets" : 2,
				"outlettype" : [ "bang", "float" ],
				"patching_rect" : [ 475.479877293109894, 628.0, 38.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "button",
				"numinlets" : 1,
				"id" : "obj-78",
				"parameter_enable" : 0,
				"numoutlets" : 1,
				"outlettype" : [ "bang" ],
				"patching_rect" : [ 129.583348870277405, 323.0, 24.0, 24.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "0.25",
				"numinlets" : 2,
				"id" : "obj-55",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 327.464286148548126, 750.535714566707611, 50.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "t b b b",
				"numinlets" : 1,
				"id" : "obj-48",
				"numoutlets" : 3,
				"outlettype" : [ "bang", "bang", "bang" ],
				"patching_rect" : [ 718.323171138763428, 535.435849666595459, 42.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "if $i2 != 0 then bang",
				"numinlets" : 2,
				"id" : "obj-65",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 718.323171138763428, 430.333339333534241, 114.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "t b b i",
				"numinlets" : 1,
				"id" : "obj-51",
				"numoutlets" : 3,
				"outlettype" : [ "bang", "bang", "int" ],
				"patching_rect" : [ 121.583348870277405, 374.971545815467834, 40.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "if $i1 == 0 then $i1",
				"numinlets" : 1,
				"id" : "obj-5",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 66.333348870277405, 266.333339333534241, 107.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "1/8 1/4 1/4 1/4",
				"numinlets" : 2,
				"id" : "obj-97",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 171.5, 327.999999165534973, 119.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "bach.nth @out t",
				"numinlets" : 2,
				"id" : "obj-10",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 197.5, 374.971545815467834, 93.0, 22.0 ],
				"saved_object_attributes" : 				{
					"versionnumber" : 80100
				}

			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "set $ 1",
				"numinlets" : 2,
				"id" : "obj-42",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 375.5, 664.484255492687225, 45.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "0",
				"numinlets" : 2,
				"id" : "obj-35",
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"patching_rect" : [ 375.5, 634.694425821304321, 29.5, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "accum 0.",
				"numinlets" : 3,
				"id" : "obj-140",
				"numoutlets" : 1,
				"outlettype" : [ "float" ],
				"patching_rect" : [ 475.479877293109894, 664.484255492687225, 57.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "counter",
				"numinlets" : 5,
				"id" : "obj-21",
				"numoutlets" : 4,
				"outlettype" : [ "int", "", "", "int" ],
				"patching_rect" : [ 482.150114238262177, 111.769229352474213, 61.0, 22.0 ]
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "- 1",
				"numinlets" : 2,
				"id" : "obj-2",
				"numoutlets" : 1,
				"outlettype" : [ "int" ],
				"patching_rect" : [ 314.823171138763428, 208.467480063438416, 29.5, 22.0 ]
			}

		}
 ],
	"lines" : [ 		{
			"patchline" : 			{
				"source" : [ "obj-13", 0 ],
				"destination" : [ "obj-2", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-97", 0 ],
				"destination" : [ "obj-10", 0 ],
				"color" : [ 0.923345446586609, 0.660886764526367, 0.115482836961746, 1.0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-91", 0 ],
				"destination" : [ "obj-90", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-9", 0 ],
				"destination" : [ "obj-2", 1 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-80", 0 ],
				"destination" : [ "obj-65", 0 ],
				"color" : [ 0.110789746046066, 0.000752151012421, 0.908478379249573, 1.0 ],
				"midpoints" : [ 453.729877591133118, 774.305683970451355, 691.455095052719116, 774.305683970451355, 691.455095052719116, 418.333339333534241, 727.823171138763428, 418.333339333534241 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-8", 0 ],
				"destination" : [ "obj-137", 1 ],
				"color" : [ 0.164321273565292, 0.745775282382965, 0.695289671421051, 1.0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-78", 0 ],
				"destination" : [ "obj-51", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-76", 0 ],
				"destination" : [ "obj-75", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-65", 0 ],
				"destination" : [ "obj-48", 0 ],
				"color" : [ 0.233483403921127, 0.0, 0.945620119571686, 1.0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-51", 1 ],
				"destination" : [ "obj-8", 0 ],
				"color" : [ 0.253721088171005, 0.870051085948944, 0.750130653381348, 1.0 ],
				"midpoints" : [ 141.583348870277405, 410.203697741031647, 475.75, 410.203697741031647 ],
				"order" : 1
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-51", 0 ],
				"destination" : [ "obj-47", 0 ],
				"color" : [ 0.175207287073135, 0.859962940216064, 0.814532220363617, 1.0 ],
				"midpoints" : [ 131.083348870277405, 406.971545815467834, 61.577383816242218, 406.971545815467834, 61.577383816242218, 100.769229352474213, 353.499998807907104, 100.769229352474213 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-51", 1 ],
				"destination" : [ "obj-35", 0 ],
				"color" : [ 0.253721088171005, 0.870051085948944, 0.750130653381348, 1.0 ],
				"midpoints" : [ 141.583348870277405, 621.137593388557434, 385.0, 621.137593388557434 ],
				"order" : 2
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-51", 1 ],
				"destination" : [ "obj-21", 3 ],
				"color" : [ 0.253721088171005, 0.870051085948944, 0.750130653381348, 1.0 ],
				"midpoints" : [ 141.583348870277405, 406.971545815467834, 54.28659600019455, 406.971545815467834, 54.28659600019455, 91.930579662322998, 523.150114238262177, 91.930579662322998 ],
				"order" : 0
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-5", 0 ],
				"destination" : [ "obj-51", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-48", 0 ],
				"destination" : [ "obj-97", 0 ],
				"color" : [ 0.130310952663422, 0.044172912836075, 0.866668939590454, 1.0 ],
				"midpoints" : [ 727.823171138763428, 576.817588031291962, 898.083332479000092, 576.817588031291962, 898.083332479000092, 304.999999165534973, 181.0, 304.999999165534973 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-48", 2 ],
				"destination" : [ "obj-21", 0 ],
				"color" : [ 0.04847402125597, 0.0, 0.700718760490417, 1.0 ],
				"midpoints" : [ 750.823171138763428, 598.956993162631989, 907.151538789272308, 598.956993162631989, 907.151538789272308, 101.119610607624054, 491.650114238262177, 101.119610607624054 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-48", 1 ],
				"destination" : [ "obj-2", 0 ],
				"color" : [ 0.0, 0.0, 0.700708031654358, 1.0 ],
				"midpoints" : [ 739.323171138763428, 587.484255492687225, 920.526524364948273, 587.484255492687225, 920.526524364948273, 84.467480063438416, 324.323171138763428, 84.467480063438416 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-47", 0 ],
				"destination" : [ "obj-2", 1 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-45", 0 ],
				"destination" : [ "obj-140", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-45", 1 ],
				"destination" : [ "obj-140", 1 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-43", 0 ],
				"destination" : [ "obj-97", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-43", 1 ],
				"destination" : [ "obj-97", 1 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-42", 0 ],
				"destination" : [ "obj-140", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-4", 0 ],
				"destination" : [ "obj-43", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-35", 0 ],
				"destination" : [ "obj-42", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-21", 0 ],
				"destination" : [ "obj-9", 0 ],
				"midpoints" : [ 491.650114238262177, 147.618354707956314, 395.5, 147.618354707956314 ],
				"order" : 1
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-21", 0 ],
				"destination" : [ "obj-122", 0 ],
				"order" : 0
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-2", 0 ],
				"destination" : [ "obj-76", 0 ],
				"midpoints" : [ 324.323171138763428, 239.418267160654068, 453.729877591133118, 239.418267160654068 ],
				"order" : 1
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-2", 0 ],
				"destination" : [ "obj-65", 1 ],
				"midpoints" : [ 324.323171138763428, 329.900409698486328, 822.823171138763428, 329.900409698486328 ],
				"order" : 0
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-2", 0 ],
				"destination" : [ "obj-5", 0 ],
				"order" : 3
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-2", 0 ],
				"destination" : [ "obj-10", 1 ],
				"color" : [ 0.0, 0.0, 0.0, 1.0 ],
				"order" : 2
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-140", 0 ],
				"destination" : [ "obj-80", 0 ],
				"order" : 1
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-140", 0 ],
				"destination" : [ "obj-80", 1 ],
				"order" : 0
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-140", 0 ],
				"destination" : [ "obj-55", 1 ],
				"order" : 2
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-137", 0 ],
				"destination" : [ "obj-45", 0 ],
				"color" : [ 0.796577215194702, 0.549795150756836, 0.086719118058681, 1.0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-132", 0 ],
				"destination" : [ "obj-137", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-132", 1 ],
				"destination" : [ "obj-137", 1 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-130", 0 ],
				"destination" : [ "obj-132", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-122", 0 ],
				"destination" : [ "obj-121", 0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-10", 0 ],
				"destination" : [ "obj-91", 0 ],
				"order" : 1
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-10", 0 ],
				"destination" : [ "obj-130", 0 ],
				"color" : [ 0.923345446586609, 0.660886764526367, 0.115482836961746, 1.0 ],
				"order" : 0
			}

		}
 ],
	"appversion" : 	{
		"major" : 8,
		"minor" : 2,
		"revision" : 2,
		"architecture" : "x64",
		"modernui" : 1
	}
,
	"classnamespace" : "box"
}
Source Audio's icon

Next time paste copy-compressed max patch.

makes it easier to use.

then, you did not precise the question.

for example, if you have a list with 20 items, and set address to 12,

does that mean that you want to output all from 11th back to 1st item ?

in that case use zl.slice and split / reverse the list at that index.

if you need a number of items from address backwards ?

then you need 2 parameters, offset and number of items...

which seems not to be the case, at least not in the patch you posted.