The expression: isequal ('', []) evaluates to true

Hello Octave,

I realize isequal ('', []) evaluates to true. Is this for compatibility or is it a bug?

octave --version outputs

GNU Octave, version 7.1.0
Copyright (C) 1993-2022 The Octave Project Developers.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

Octave was configured for "x86_64-pc-linux-gnu".

Additional information about Octave is available at https://www.octave.org.

Please contribute if you find this software useful.
For more information, visit https://www.octave.org/get-involved.html

Read https://www.octave.org/bugs.html to learn how to submit bug reports.

I suspect its for compatibility. Similarly, isequal(true, 1): so isequal does not care about data type (?) and since both '' and [] are 0x0, they are the same…

Also I noticed: isequal('a', 97) is true (b/c double('a') == 97).

I think it would be useful if help isequal said some of this! Is there an issue on Savanah about this?

I guess for now we can use

istrulyequal = @(x, y) isequal (class (x), class(y)) && isequal (x, y);

for true equality…

Yes. It is intentional specifically for compatibility. From the matlab help for isequal:

Notice that isequal does not consider data type when it tests for equality

2 Likes

So indeed let us improve our docs. @alexvong1995 please file an issue at Savanah so this doesn’t get lost.

1 Like

looks about right. Perhaps one-off inline solution to for our specific downstream issue?

oops sorry this system seems to be a linear thread… my “looks about right” was in reply to @alexvong1995 's anonymous function

…which is indeed already done in private/store_vars_in_python: Fixes regression... by alexvong1995 · Pull Request #1153 · cbm755/octsympy · GitHub