#1058 Array declarations, use

lel4866 Sun 4 Apr 2010

Hi -

As someone new to fantom, I just spent quite some time trying to figure out how to do something I thought would be quite simple. The good news is that I figured it out. But (obviously there is a but or I wouldn't be posting this), I think this should be much simpler, both from a documentation and an implementation stand point.

The problem is, how to declare and use an array with, say, 1000 elements.

My solution:

Float[] prices := [,]
prices.fill(0.0f, 1000)
prices[2] = 5.0f

Am I missing something? Is there no one line way of declaring and initializing an array of 1000 elements?

In any event, even if I missed the proper way, I think array usage is so common that it could be quite a bit more evident in the docs.

Thanks.

helium Sun 4 Apr 2010

Creating a list with 1000 elements in one line?

prices := Float[,].fill(0.0f, 1000)

Most methods return This in Fantom (or the magic L in the case of lists, which is basically the same there).

lel4866 Sun 4 Apr 2010

Works for me! I added this to DZone Snippets

Login or Signup to reply.