Comparing Perspective Object - Never the same?

I thought it would be easy to compare two array object in Perspective. I was wrong.
I had to implement an unnecessarily long script to compare them and return True, but this fails when attempt to do it with expression bindings.

Here an example. I have two label component with a custom array property that is literally a copy.
image
image
image

When I attempt to compare with

if({../Label.custom.array}={../Label_0.custom.array},'Same','Different')

I get that is different, why?
image

The expression equals operator is using ‘shallow’ quality; under the hood, for various reasons, this is ultimately becoming a simple identity check.

We could potentially make this smarter in the future, but it won’t help you much right now.
In the short term, you can lean on Python a bit; use runScript to convert Perspective types to equivalent Python representation, then run your equality comparison on those:

def sanitize_tree(element):
    if hasattr(element, '__iter__'):
        if hasattr(element, 'keys'):
            return dict((k, sanitize_tree(element[k])) for k in element.keys())
        else:
            return list(sanitize_tree(x) for x in element)
    return element

def deepEquals(left, right):
    return sanitize_tree(left) == sanitize_tree(right)

(see this post for more on the sanitize_tree function)

Can be used basically the same as your existing:
runScript("utils.deepEquals", 0, {view.custom.left}, {view.custom.right})
java_87kXhe
java_HTQddC
java_avv9fA

1 Like

Oh, the shallow copy never can to my mind. That has sense
Nice, yes I did a similar script but also comparing lengths.

Thanks for the knowledge.

In 8.1.16 comparison between arrays in expressions will work 'as expected':

1 Like

Great news, thanks for sharing the changelog!