Dan Sugalski wrote:
> On Wed, 30 Aug 2000, Jeremy Howard wrote:
> > Furthermore, if it has a single basic data type and is declared
':compact'
> > it should be stored in a contiguous block of memory.
>
> If you do a plain
>
> my int @foo;
>
> it'll end up with a contiguous block of memory anyway. :compact seems to
> me more an attribute for sparse arrays than anything else.
>
Yes, but I'm talking about a list ref of list refs. From my post yesterday:
$a = [[0,1,2],
[3,4,5]];
@b = @$a[[0,1], [1,2]]; # @b == (1, 5)
We should be able to declare that $a is a ref to a compact matrix of ints.
> > Finally, I believe that
> > we need to adjust RFCs for reduce(), list generation, and
> > zip/unzip/partition/reshape to work with n-dim matrices.
> >
> > Oh, and we also would need to look at how we can hide as much of the
> > dereferencing as possible.
>
> If multi-dim arrays get in, there won't *be* dereferencing. This:
>
> $foo[1;2;3]
>
> will directly access an array element. Couple of quick multiplications an
> a base pointer add and pow--you get your referenced element.
>
My proposal is that lists of list refs _are_ multi-dim arrays.
$foo[[1,2,3]];
directly accesses an array element, as does:
$foo[1][2][3];
To get at multiple elements you use:
@foo[[1,2,3], [4,5,6]];
or:
@foo[1,4][2,5][3,6];
Although they look and act like list ref trees, they should be implemented
as direct tensors. This should be easy as long as we can declare their
elements as being of a single simple type.
I don't see the need for an additional multi-dim type, or for the ';'
syntax. It will be _much_ easier to manipulate lists if we can index them
with standard list refs:
@3d_diag_slice =
partition(3, zip(1.., 1.., 1..)); # ([1,1,1],[2,2,2],[3,3,3],...)
@a_diag = @a[@3d_diag_slice]; # Where @a is a 3d matrix/list ref tree
@slice_by_2 = (1..:2); # (1,3,5,...)
@b_slice = @b[@slice_by_2]; # Where @b is a 1d array/list ref
I'm still not actually sure whether n-dim matrices should be references:
$a = [[0,1,2],
[3,4,5]];
or whether they should just be lists:
@a = ([0,1,2],
[3,4,5]);
In the first case, we need to add dereferencing syntax all over the place.
In the second case, the actual elements of the list need derefencing syntax.
The trick is to pick one of these options, and then try and work out what
_implicit_ dereferencing should take place. Note that I'm only talking about
_syntax_, not _implementation_--the elements should still be accessed
directly.