List equality
Issue #163
resolved
Following code blocks evaluate to false:
Comments (7)
-
repo owner -
Most programming languages will report false to
[1, 2, 3] = [1, 2, 3]
, but I see the pedagogical value in that. In Snap_!_ we do have list comparison. It is recursive and it avoids circular references.Here’s Jens' implementation in case we want to base ours on that one: https://github.com/jmoenig/Snap/blob/master/src/lists.js#L545
-
reporter Here is the SNAP! version:
-
repo owner - marked as proposal
-
Maybe a makeshift
-
repo owner Clever idea!
But inspired me to add a "list _ equals _" block to the list library that does a fully recursive list comparison. That will be in the next pilot release.
-
repo owner - changed status to resolved
You can now use the "list _ equals _" block from the Lists library to test for list equality.
- Log in to comment
This is worth thinking about. It would need to be recursive to handle lists inside of lists, and a recursive implementation would need to protect itself against circular data structures.
But perhaps a non-recursive implementation would be better than nothing. That would deal the case above and probably 95% of beginner situations. And those advanced enough to build more complex data structures could write their own recursive equality test.