I was testing some script to allow variable function name. And suddenly found very confusing result for this short script. Tested on ROS 6.49 and 7.6. Can someone explain how it works?
I know about semicolons. that’s doesn’t matter, i prefer C-like style writing.
Routerboard info is above in my initial post, but this behavior is observed on different devices.
I was finding a way to have a global function with generated name (stored in variable).
Smth. alike (not working):
replace long chain of statements like “1 + 1 + 1 + 1 + 1” with a chain that does the same thing, but shorter like “1 × 5” (just an example)
fix $ error after :set and added missing { } for terminal.
{
:local cookie "someName"
:local cookieCode do={:put "TestIt"; /system routerboard print}
# create a function called cookieCode and the function do what is present between the { }
[[:parse ":global $cookie"]]
# is like >:global someName<
# what this do: on parse session define global variable someName with "nothing" value
[[:parse ":global $cookie; :set $cookie \"\""]]
# is like >:global someName; set someName ""<
# what this do: on parse session define global variable someName with "nothing" value,
# and later set someName global variable = to "" (empty string)
/system script environment remove [find where name=$cookie]
# what this do: remove global variable "someName" from environment
}
But we don’t give a damn about all this, in reality what we notice is that the function is called even if it is never written to use it:
For extremely synthesize the compiler bug:
[9b184@MATRIX] > :local test do={:put “WHY\3F\3F\3F”};;
WHY???
[9b184@MATRIX] >
Part two is just the same as part one, just multiplied:
{
:local test1 do={:put “test1”}
:local test2 do={:put “test2”}
:local test3 do={:put “test3”}
:local test4 do={:put “test4”}
:local test5 do={:put “test5”}
}
on second call all function defined before are executed…
Temporary (I hope) fix: assign the returned value to one useless variable: