"add items to list" or "for each item in list" problem

222 views
Skip to first unread message

Rudolph Karstadt

unread,
Apr 15, 2017, 6:00:46 PM4/15/17
to mitappinv...@googlegroups.com
Hi,
I spent some time with searching an issue in my program, until I found a strange (may be only for me) behavior with the "for each item in list" block.

I work with a List in List "L_A"  e.g. ((A.B.C.D) (E,F,G,H) (I,J,K,L))  


Now I want to get another list "L_B" without the 2nd item of every list B ,F ,J  -> ((A,C,D) (E,G,H) (I,K,L))

So I add each list (item) to the "L_B" 
and then remove the 2nd item from "L_B"
That works...
...BUT    that also removes the 2nd item from the "L_A"

after some time of trying I found, that I have to 'separate" "L_A" with the "copy list list" block from the "each item in list" loop. (Button2) I've never seen this before.


Now I tried the "for each number" loop instead and I have the same problem.
now I have to separate the list "L_A" from the "add items to list" block with the copy list block.

In this example the list '"L_A" is affected by the remove block list ->"L_B" 'through' the add and the select block -> 'L_A' (without copy list)
that is hard to understand for me.

ListInLIst_Test.aia

Abraham Getzler

unread,
Apr 15, 2017, 9:45:02 PM4/15/17
to MIT App Inventor Forum
You have discovered that AI2 lists store references to other lists.

This makes updating lists within lists aggravating,
as you have discovered.

I try to avoid the aggravation by storing  CSV strings as my rows
in a table, to stay 1-dimensional.

I also use value functions to return updated copies of 
whatever row I need to update.

For a deep dive into list wierdness, see this Ouroborous 
sample in the Gallery - an infinitely deep list.



ABG

Rudolph Karstadt

unread,
Apr 16, 2017, 3:21:35 PM4/16/17
to MIT App Inventor Forum
Thank you for your answer.

Now I learned this and I can 'fix' it with the help of the copy list in list block


greetings Rudolph
Reply all
Reply to author
Forward
0 new messages