First, let’s see what happens if one casts an existing normal array to an array using :toarray:
{
:local a (1,2,3);
:local b [:toarray $a];
:put "a is $[:typeof $a] len $[:len $a]:";
:put $a;
:put "b is $[:typeof $b] len $[:len $b]:";
:put $b;
:put "equiv...";
:if ($a=$b) do={:put "yes"} else={:put "no"}
}
OUTPUT:
a is array len 3:
1;2;3
b is array len 3:
1;2;3
equiv...
yes
NOW just change the initialization of the array to an associative array (I’m running RouterOS 6.22, FYI):
:local a {"a"="A";"b"="B";"c"="C"};
BUGGY? OUTPUT:
a is array len 3:
a=A;b=B;c=C
b is array len 0:
equiv...
no
It sure seems to me that casting an associative array using :toarray should leave it unchanged.
(Please don’t ask the naive question “Why would you ever need to cast an array to an array if it’s already an array?” Asking that likely means you’ve not tried writing robust scripts that expect an array as input but can gracefully handle non-array data too in certain cases. If casting had worked as expected, then it would permit handling input data in several forms without having to add code to test input data types.)
Is this a bug?
Wondering…
Aaron out.