[Pharo-project] Question about #becomeForward

Sven Van Caekenberghe sven at beta9.be
Wed Jan 18 09:03:55 CET 2012


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

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

I thought that the following would work

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

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

	| 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 ?



More information about the Pharo-project mailing list