Take a look at the attached flow. In the first assignment, variables a and b end up pointing to the same list (i.e. the same memory location). Is that the intended behavior? It's a little counterintuitive, especially if you use setValue("b", getValue("a", null)) instead of the assignment operator. I expect both to make b contain a separate copy of the list, not point to the same list.
Is this documented anywhere? I couldn't find it. Thanks.
http://automagic4android.com/flow.php?i ... 30f53e6257
List Variables Are Pointers, Not True Variables
Moderator: Martin
Re: List Variables Are Pointers, Not True Variables
Yes, this is the intended behavior. A variable is a reference (like a pointer but you can not do pointer arithmetic). Assigning a list within a variable to another variable does not automatically create a copy of the list.
Function x=getValue("a", null) returns the value stored in variable a and is more or less the same as executing x=a. The getValue has the slight advantage to access dynamically built variables like this:
b = "test"
x = getValue("x"+b, null); //to access variable xtest
It's not documented yet, I will add a short paragraph.
Function x=getValue("a", null) returns the value stored in variable a and is more or less the same as executing x=a. The getValue has the slight advantage to access dynamically built variables like this:
b = "test"
x = getValue("x"+b, null); //to access variable xtest
It's not documented yet, I will add a short paragraph.
Re: List Variables Are Pointers, Not True Variables
What, then, is the recommended way to make a copy of a list? I guess it would have to be a for-loop. And I can't think of any way at all to do that for a map without knowing its keys ahead of time.
Also, is there any way to acquire a variable's (or a list element's or map entry's) type? For example, if I create a map "{a=1,b=2}" and a string "{a=1,b=2}", I can treat the map as a string but I can't treat the string as a map. I'd like to write a script that nicely formats variables for debugging but without knowing types ahead of time there would be a lot of complex parsing involved.
Also, is there any way to acquire a variable's (or a list element's or map entry's) type? For example, if I create a map "{a=1,b=2}" and a string "{a=1,b=2}", I can treat the map as a string but I can't treat the string as a map. I'd like to write a script that nicely formats variables for debugging but without knowing types ahead of time there would be a lot of complex parsing involved.
Re: List Variables Are Pointers, Not True Variables
Here's a script snippet that creates two maps that cannot be distinguished by looking at them in a Debug Dialog:
map1 = newMap();
b = "s";
addMapEntry(map1, "b=b, r", b);
map2 = newMap();
b = "b";
r = "s";
addMapEntry(map2, "b", b);
addMapEntry(map2, "r", r);
Without a way to extract a map's keys, there's no way to tell the two apart.
I'd like to request some new functions:
List getMapKeys(Map aMap)
It would return a List containing all the keys for the given map.
Also:
String typeOf(String variableName)
It would return the data type of the variable named "variableName".
And:
Map copyMap(Map aMap)
List copyList(List aList)
For duplicating Maps and Lists.
Just for your consideration. Thanks!
map1 = newMap();
b = "s";
addMapEntry(map1, "b=b, r", b);
map2 = newMap();
b = "b";
r = "s";
addMapEntry(map2, "b", b);
addMapEntry(map2, "r", r);
Without a way to extract a map's keys, there's no way to tell the two apart.
I'd like to request some new functions:
List getMapKeys(Map aMap)
It would return a List containing all the keys for the given map.
Also:
String typeOf(String variableName)
It would return the data type of the variable named "variableName".
And:
Map copyMap(Map aMap)
List copyList(List aList)
For duplicating Maps and Lists.
Just for your consideration. Thanks!
Re: List Variables Are Pointers, Not True Variables
Good idea, I add the functions to the todo-list.
Thanks & Regards,
Martin
Thanks & Regards,
Martin