Create 2-D array of strings with nested fill

Viewed 46

I am initializing a vector of strings like this

mask = fill(fill(' ', maxx), maxy)

in order to then populate it by setting individual elements:

mask[y][x] = '·'

This doesn't work: I get maxy times the same string. I guess the outer fill just creates a list of pointers to the Vector created by the inner fill (the documentation of fill! confirms this explicitly). What should I do instead?

1 Answers

One solution is to use a list comprehension like this:

mask = [fill(' ', maxx) for y in 1:maxy]

(But I'd still be interested to learn whether there is a solution with fill.)

Related