[Newbies] A do with ONLY index? (plus,. a style question)

Blake blake at kingdomrpg.com
Sun Feb 4 01:44:12 UTC 2007

In a Sequencable collection, doWithIndex seems to just call withIndexDo.  
Is there a "do" that passes just the index, not the object?

My son is working on a roguelike, and we're looking at various ways of  
creating the map. This is a two-dimensional map that would fit in a  
character-mode, and we have this so far:

| map xBound yBound |
xBound := 80.
yBound := 24.
map := Array new: xBound.
i := 1.
[i <= xBound] whileTrue: [
	map at:i put: (Array new:yBound).
	i := i + 1

map do: [ :col|
	col withIndexDo: [:obj :y|
		col at:y put:#stone.

This seems to lack elegance. Better would be:

map := 2DArray new: 80 at 25.
map doXY: [:xy| map atXY:xy put:#stone].

Or even:

grid := Grid new: 80 at 25 fill: #stone.

Marcus has his 2DArray but it's peppered with caveats.



More information about the Beginners mailing list