Hi,

I want to create an array that references itself in its second element like this

| array |
array := #(1 nil).
array at: 2 put: array.
array

I thought that the following would work

| array elements |
array := Array new.
elements := Array with: 1 with: array.
array becomeForward: elements.
array

And it does in a workspace, but not in my code where it looks like this

parseArray
        | array elementsArray |
        array := Array new.
        self storeReference: array.
        elementsArray := self parseArrayInternal.
        elementsArray size > 0 
                ifTrue: [ array becomeForward: elementsArray ].
        ^ array

The #become[Forward] is necessary because the array size is not known up front 
and one of its elements might refer to itself, possibly deeper down.

So I guess I am doing something wrong, the question is what ?

Or is there another way to achieve the same effect ?

Thx,

Sven

Reply via email to