Lists linking

  1. What browsers show this problem?
    Google Chrome
  2. Please share an example project (if possible).
  3. Describes the steps to reproduce this issue.
  4. What does Snap! currently do?
    Adds ['i'] to both lists.
  5. What should Snap! do instead?
    Only add ['i'] to (a) list

Hi @biran4454,

This is not a bug, it's the behavior of Snap! lists. Lists are mutable data structures. A list maintains its identity even when items are added, removed, or replaced.

So, when you do "Set (b) to (a)" and "a" is a list, you are not copying static a content, you are pointing to the same list element.

If you want to copy a "list content" you can use some "list reporters". For example:

That's all,


Actually, it's not just about lists, it's about how variables work in general.

It'll probably be more obvious to you with this example:


If Snap! did what you suggest, then we'd end up with two copies of the sprite, which clearly doesn't make sense.

A variable is not a box where you put a unique thing, but just a name or a label you give to a value. The same value can be labelled hundreds of times, and it will always remain separate from the label.

A and B reference the same list.
See the Snap help dialog for "is identical to" (Operators) for more information.

OK, thanks everyone! That information will help a lot in future coding. Thanks!
P.S. what do I label this if it's not a bug?

You're welcome.

Hmm. I guess it could either go to Help with Snap! or Computer Science.