[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: newbee question...
- From: Jonathan Adamczewski <jadamcze@...>
- Date: Thu, 19 Oct 2000 10:09:49 +0000 (GMT)
On 19 Oct 2000 KZerbe@t-online.de wrote:
> > How can I implement a USER-friendly method to work with
> 2-dimensional
> > arrays/matrices. (i.e. create, redim, access elements etc.)?
> > I'd like to allow my users to do something like:
> > arrayA = array(NumCols, NumRows) --create array
> > numberB = getval(arrayA, Col, Pos) --access elements
> > redim(arrayA, ColDelta, RowDelta) --realloc
> > arrayC = arrayA -- copy whole array
> > arrayD = arrayA+arrayB --arithmetic operators
> >
> > Do I have to use the USERDATA tag for arrayA, arrayB ..., or can I do
> all
> > this with tables?
> >
>
> Forget the unflexibility of "legacy programming languages" like maybe C
> or BASIC (>>yuck<<).
> You need not to "redimensioning" anything. Just add new elements- or
> even dimensions. Even don't think about indexes being contigous
>
> -A table can contain tables, so one solution for two dimensional
> matrices can be a table of tables
> -you don't have to specify a size ever
> - to cleanup, just assign nil or leave the scope where the table
> is valid, the garbage collector does the rest
>
Out of curiousity...
> c={1,3}
> print(c[0])
nil
> print(c[1])
1
> print(c[2])
3
>
Why does table indexing begin at 1 and not zero? I guess this is just a
convention, but I've become accustomed to zero based arrays :)
Thanks
Jonathan.