variable reference not working in v7

1、array reference test

:log warn "===Array reference test start...==="
:local arr1 [:toarray ""]
:local arr2 [:toarray ""]

:set ($arr1->"key1") 2

:log warn ("arr1 befare change=")
:log warn $arr1

:set ($arr2->"key2") $arr1

:set ($arr1->"key1") 3

:log warn ("arr1 after change=")
:log warn $arr1

:log warn ("arr1 in arr2(case1)=")
:log warn ($arr2->"key2")


:local tmparr ($arr2->"key2")

# get array from array2, and modify it.
:set ($tmparr->"key1") 4

:log warn ("arr1 in arr2(case2)=")
:log warn ($arr2->"key2")

:log warn "===Array reference test end...==="

The result(v6 vs v7):
arr test compare.PNG
It seems that when you put an array into another array, it will make a copy then put the new array into target array in v7. But in v6 it doesn’t make copy and just put it self into target array.
When get element from the array and modify it, you will get different result between v6 and v7(case2)

2、function parameter reference test

:log warn "===Function parameter test start...==="

:global func1 do={
    :log warn "func1: p1 before change="
    :log warn $p1

    :set ($p1->"key1") 5

    :log warn "func1: p1 after change="
    :log warn $p1
}


:local arr1 [:toarray ""]

:set ($arr1->"key1") 2

:log warn "arr1 before call function="
:log warn $arr1

$func1 p1=$arr1


:log warn "arr1 after call function="
:log warn $arr1

:log warn "===Function parameter test end...==="

The result(v6 vs v7):
func test compare.PNG
In v6, some type of variable(ex: array) can be passed as parameter to function, the you can modify the variable in the function, and the caller will get the same result for the variable which passed as parameter. It seems that this behavior was changed in v7.

So for the results of the tests above, which one is expected behavior? v6 or v7?

I have some scripts use the reference feature in v6 and hope it will also work on v7, thank you.

Just read the already existing posts, even mine.

In v6 it happened by mistake, in v7 this error has been fixed.
What happens in v7 is the right behavior.
There are no “pointers” in RouterOS as understood in some programming languages.
Is present “op”, one operational pointer that work as shortcut for complex array:
http://forum.mikrotik.com/t/persistent-environment-variables/145326/6

All data types on RouterOS:
http://forum.mikrotik.com/t/structured-ipv6-address/168153/7

Hi rextended, thank you for your reply.

In v6 it happened by mistake, in v7 this error has been fixed.

But this will broke compatibility,and maybe very hard to fix(hard to find out where need fix).


There are no “pointers” in RouterOS as understood in some programming languages.

Yes, it just like “pointers”, and as the test code shows, i thought it exist in ros, but to my surprise, as you said, it’s a mistake in v6.

By the way, any other information about this change(ex: release note?)

no release note…
you have to trust what I write…