Initially empty list

B starts out empty, but in the full application, points would be added by actions later. C is a list of points. D is the combination of B & C through a 2-D list comprehension, but unfortunately, it breaks when B is empty. I expected the list comprehension to produce an empty list when any of its generators are empty.

Screenshot 2023-10-31 at 9.34.22 PM

But wait, there’s more. E is intended to be the first element of B combined with C, or an empty list when B is empty. I tried two ways, but no luck.

Adding any point, say (0,0), to B makes everything work. But I need it to work with B initially empty.

By the way, this all works if I replace points by scalars.

I assume that Desmos thinks of lists as containing numbers by default, and only ‘knows’ it contains points once there’s a point in it. I guess the two best workarounds would be to either have B=[(0,0)] initially, and then make sure that your action replaces that value when it is fired first of all; or to have lists B_x (empty), B_y (empty), C_x (all 1s), C_y (1…5), which are combined into D as ((bx+cx,by+cy) for bx=B_x, cx=C_x, …)

1 Like

Yes, thanks. I had settled on the first, but finding an acceptable bonus point has been tricky and led to some bugs, so I was looking for a cleaner solution.

Alternate workaround, is to have an undefined point in your list:

B= [(1/0,0)]

You may just want your action to replace B using some sort of counter (instead of list length), so there’s only the new points added.


Yeah, I tried that. My bonus point was (Inf,inf), but compensating code is necessary. You compensated with a counter; I did it another way (adapting some interacting code in the real application: King’s Move).

You could also have the initial point in list B and change your definition of b:

D= [ b+c for b=B[2...max(2,length(B))],c=C ]

In the actual code, B is used nine times.

At this point, I’m happy with the bonus point (inf,inf) and the one minor adjustment necessary.

Thanks again!

1 Like