|
Derar Novice
Joined: 09 Sep 2006 Posts: 44
|
Posted: Thu Jul 29, 2010 7:57 pm
[3.22] BUG: %replaceitem always inserts values as type String |
Regardless of what you try to tell %replaceitem to put into a list, it always inserts a string value.
This means that you can never use %replaceitem to insert numbers or nested list elements.
To replicate:
Code: |
TestList = 1|2|3
#SHOW %json(@TestList)
TestList = %replaceitem(4, 1, @TestList)
#SHOW %json(@TestList)
TestNest = "[[41,25],32,81]"
TestNest = %json(@TestNest)
#SHOW %json(@TestNest)
TestNest = %replaceitem(12|21, 2, @TestNest)
#SHOW %json(@TestNest)
TestNest = %replaceitem("[24,48]", 3, @TestNest)
#SHOW %json(@TestNest)
TestRep = "[24,48]"
TestNest = %replaceitem(%json(@TestRep), 1, @TestNest)
#SHOW %json(@TestNest)
|
Outputs:
Code: |
[1,2,3]
["4",2,3]
[[41,25],32,81]
[[41,25],"12|21",81]
[[41,25],"12|21","[24,48]"]
[[24,48],"12|21","[24,48]"]
|
This causes problems with trying to pull replaced list elements for numeric comparison/evaluation, and the obvious issue of the nested element not actually being nested.
EDIT: Totally just noticed the last %replaceitem(%json()) snipped actually worked. However, a little more testing shows that using %int or %number or similar functions does not fix the number aspect of it.
D |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Jul 30, 2010 4:34 pm |
That is correct because you are using " quotes around your values, which forces CMUD to treat them as string values and not list values. Here is the proper syntax code to test to show that %replaceitem *does* create nested lists:
Code: |
List = {1|2|3}
#SHOW %json(@List)
Nested = {a|b|c}
#SHOW %json(@Nested)
NewList = %replaceitem( @Nested, 1, @List)
#SHOW %json(@NewList)
Nested = %json("[d,e,f]")
NewList = %replaceitem( @Nested, 1, @List)
#SHOW %json(@NewList)
NewList = %replaceitem( {4|5}, 1, @List)
#SHOW %json(@NewList) |
properly shows the output:
Code: |
[1,2,3]
["a","b","c"]
[["a","b","c"],2,3]
[["d","e","f"],2,3]
[[4,5],2,3] |
So you need to remember to put {} around your string list values and not " quotes.
Now, your issue about numbers is correct and is definitely a bug, so I'll add that to the bug list. |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|