Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1125 'empty' method doesn't seem to work for .Array objects

None
invalid
Rick McGuire
None
none
1
2012-10-07
2012-10-07
Staffan Tylen
No

The documentation states that the 'empty' method "removes all items from the array".
The example shows: a~empty -- a = .array~new

The following code without 'empty' works:

t=.table~new
a=.array~new
a~append("a1")
a~append("a2")
t["t1"]=a

say t["t1"][1] -- should show 'a1'

a=.array~new
a~append("a3")
a~append("a4")
t["t2"]=a

say t["t1"][1] -- should show 'a1'
say t["t2"][1] -- should show 'a3'

a=.array~new
a~append("a5")
a~append("a6")
t["t3"]=a

say t["t1"][1] -- should show 'a1'
say t["t2"][1] -- should show 'a3'
say t["t3"][1] -- should show 'a5'

The following variation using 'empty' does NOT work:

t=.table~new
a=.array~new
a~append("a1")
a~append("a2")
t["t1"]=a

say t["t1"][1] -- should show 'a1'

a~empty
a~append("a3")
a~append("a4")
t["t2"]=a

say t["t1"][1] -- should show 'a1'
say t["t2"][1] -- should show 'a3'

a~empty
a~append("a5")
a~append("a6")
t["t3"]=a

say t["t1"][1] -- should show 'a1'
say t["t2"][1] -- should show 'a3'
say t["t3"][1] -- should show 'a5'

The use of the table in the sample code above may or may not be important, it's included because the problem initially showed up using the coding technique shown here.

ooRexx 4.1.2 (28 Aug 2012) 32-bit Windows 7

Discussion

  • Staffan Tylen
    Staffan Tylen
    2012-10-07

    Please note: the brackets seem to have been removed while posting. The sample code is attached here instead.

     
    Attachments
  • Rick McGuire
    Rick McGuire
    2012-10-07

    This is working correctly. The empty method removes all items from the array, it does not allocate a new array item. As a result, all of your table entries are pointing to the same array object, so all of your changes show up regardless of which table index you use to access the array.

     


Anonymous


Cancel   Add attachments