/*
The following program illustrates a behavior of Indexed Strings that "surprised" me. An indexed string IRx has the following indices set: ["A"], ["B"], ["A", 1], ["A", 1, 2] and ["B", 1, 2] These elements are then displayed twice: directly, and then using a loop with the "OVER" keyword. The surprising behavior is that the element ["B", 1, 2] is accessible in the direct display, but not when using the loop. Obviously, the proximate cause is the failure to define indices ["B", 1], and I can see that this is not necessarily a bug. Still it is a disturbing result and seems to deserve some insightful exegesis in NRL. One other item. The direct display "knows" that the value of IRx ["B", 1]="B", I guess because IRx["B"]="B" overrides the default for IRx ("?"). Again, the loop does not know. Perhaps more could be said about this. */ -- Program IRx.nrx IRx = Rexx "?" -- indexed rexx variable IRx["A"] = "A" IRx["B"] = "B" IRx["A", 1] = "A1" -- don't set indices ["B", 1] IRx["A", 1, 2] = "A12" IRx["B", 1, 2] = "B12" Say Say "Directly display set values" Say Do Say ' IRx["A"] =' IRx["A"] Say ' IRx["B"] =' IRx["B"] Say ' IRx["A", 1] =' IRx["A", 1] Say ' IRx["B", 1] =' IRx["B", 1] Say ' IRx["A", 1, 2] =' IRx["A", 1, 2] Say ' IRx["B", 1, 2] =' IRx["B", 1, 2] End Say Say "Display using the 'OVER' keyword" Say Loop j1 Over IRx Say " IRx["j1"]="IRx[j1] Loop j2 Over IRx[j1] Say " IRx["j1", "j2"]="IRx[j1, j2] Loop j3 Over IRx[j1,j2] Say " IRx["j1", "j2", "j3"]="IRx[j1, j2, j3] End End End Say /* Program displayed Directly display set values IRx["A"] = A IRx["B"] = B IRx["A", 1] = A1 IRx["B", 1] = B IRx["A", 1, 2] = A12 IRx["B", 1, 2] = B12 Display using the 'OVER' keyword IRx[A]=A IRx[A, 1]=A1 IRx[A, 1, 2]=A12 IRx[B]=B */ _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
I don't think this is a bug but it may need more explicit
documentation of how it works.
Rexx objects are actually only indexed in a single dimension. When you use multiple indexes, you are following a "chain" of Rexx objects. Since your item ["B", 1] was never created, it does not really exist and there is no element to return for your LOOP OVER code segment. The direct reference to it returns the default value from item ["B"]. However when you created item ["B", 1, 2], a "ghost" node for ["B", 1] was defined in the hashmap chain to set that element, hence a direct reference can locate it. Since that behavior might surprise some, I recommend that you open a tracking issue on Kenai: https://kenai.com/projects/netrexx That will remind us to discuss possible solutions and documentation. -- Kermit On 7/15/2014 6:05 AM, George Hovey
wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Free forum by Nabble | Edit this page |