How about Smalltalk-2000?

John Clonts jclonts at mastnet.net
Thu Feb 17 05:10:07 UTC 2000


Alan Reider wrote:
> 
> >Well, what about these array operations:
> >
> >a[5] := 10                                     " obvious array syntax "
> >a[5][9] := 0                         " multiple levels of arrays "
> >a[0:10] := 0                           " initialize a slice "
> >a[5:10] := b[10:15]                    " slice "
> >a["key"] := Value                      " dictionary "
> >
> >Warren
> 
> As an aside, here is a simple idea for a multidimensional array which reads fairly well, just using objects and the existing ST syntax:
> 
> array := MultiArray dimensions: 5,9 .
> array at: 5,9 .
> array at: 5,9 put: 0.
> array at: 3,10. " == array at: 4,1 "
> 
> I appropriated #, in Integer to create instances of a class called Subscript. A subscript is essentially an array of index values. Implementing #, in Subscript allows using this shorthand for more than 2 dimensions, eg 5,9,3.
> 
> This shorthand is expensive (instantiates objects) but a single subscript object could be used (eg in a loop) by sending it messages like #next or #next: dimensionToScroll.
> 
> A MultiArray is basically an Array (or has an Array) with the addition of a subscript which defines the dimensions.
> 
> All index math eg translating Subscripts into linear indexes is encapsulated in Subscript. So
> 
> MultiArray>>#at:  looks like
> 
> at: aSubscript
> 
>     ^self contents at: (aSubscript linearIndexIn: self dimensions)
>         "or, (self dimensions at: aSubscript) "
> 
> Subscripts and MultiArrays could also be taught to do many other things, eg slices.
> 
> -alan reider

Is this any better (to speak of ) than using Points:

array at: 5 at 9 put: 123.

?

Cheers,
John





More information about the Squeak-dev mailing list