You can test this pre-release here: https://github.com/M2000Interpreter/Environment/releases/tag/Ver12Rev3
New type of arrays using [ ]
These arrays are different, they are based on RefArray class, and can be any type, numeric and string. Can be one dimension or two. But it isn't the same as the normal array. So a 2X3 array has two arrays of 1X3 (Normal arrays are flat inside, 1x6, for the example, and the mArray class handle the indexes according the Dimension definition).
Also the editor fixed for colorize these types. We can use them in classes also, and with pointers to objects. Actually, the V member has no [ ], so we can refer to V as is (without indexes) and that is the raw object, (the RefArray) which have some useful properties, like ArrPtr (which return the memory address of the first item (for each row). Also these arrays can expand easy, by using indexes greater than the last greater index. Also these arrays may expand in both dimensions and maybe some rows have different size. We can use a definition like this:
Long Long LL[99][99] and we take a 100X100 array of Long Long (64 bit, 8 bytes each).
There is no operators like +=, so to increase 1 to 5th element in 3rd row, we use:
LL[0][4]=LL[0][4]+1
We can extract a copy of 3rd row
M=LL[2]
We can get a copy of 100X100 items
M=LL[]
We can get just a pointer
M=LL
class alfa {
string V[4]
}
A->alfa()
A=>v[0]="ok"
? A=>v[0]
Using variant we can change type per item.
class alfa {
variant V[4]
}
A->alfa()
A=>v[0]="ok"
? A=>v[0]
A=>v[0]=123456789012345678&&
def typ$(x)=type$(x)
? A=>v[0], typ$(A=>v[0])="Long Long"
Using a simple group, we can pass the pointer to sub alfa()
group A {
string V[4]
}
A.v[0]="ok"
? A.v[0]
alfa(a.v, 0)
? A.v[0]
alfa(a.v, 1)
? A.v[1]
sub alfa(b, x)
b[x]=b[x]+"..."
end sub
A string array use a 4 byte pointer for each string,. A variant type like the tuple below, use 16 bytes for each item (for string use only 2 bytes type+ 4 bytes pointer from the 16 bytes). So the above code produce 1/4 for memory which aren't string data. comparing with the default variant size array of M2000.
group A {
V=("","","","")
}
link A.v to A.v()
A.v(0)="ok"
? A.v(0)
alfa(&a.v(), 0)
? A.v(0)
alfa(&a.v(), 1)
? A.v(1)
sub alfa(&b(), x)
b(x)=b(x)+"..."
end sub
More tests here
c$="ok!!!"
global string k[10], s=string$(c$,4)
? s
m=k
m[2]="ok"
? k[2]
class alfa {
// k[] is a copy of array k
variant z=k[], m
// k is a pointer to array
variant z_ponter=k
Long long k[99]
}
alfa->alfa()
? alfa=>z[2]
alfa=>m=(1,2,3,4,5,6,7,8)
? alfa=>m
alfa=>m=1000
? alfa=>m
m[2]="ok1234"
? alfa=>z[2]<>m[2]
? alfa=>z_ponter[2]=m[2]
pk=alfa=>k
for alfa {
? len(.k)=100, type$(.k[0])="Long Long"
.k[0]=1
.z[2]="ok...this is z[2]"
}
? pk[0]
alfa=>k[0]=alfa=>k[0]+1
? pk[0]
? alfa=>z[2]
The above arrays have always 0 for the first item.
The nArray which handle dimensions (max 10), can combine with refArray so we have these types (which are mArray class, but have a connection with a RefArray class)
The mArray interface and the M2000 Interpreter utilize interesting operators, here we use the *=. The 0% literal is type of Integer (2 bytes). Also there are some function with hashtag, which are get the output (for mArray) and can produce another array (here we use the #REV() function, to get the reverse order, as a copy of the original one.
This is the example DIMVER12 in Info.gsb (exist in the setup file).
dim base 1, M(10) as integer=10
? M()
Mult=lambda (n as integer)-> {
//dim base 0, M(n) as integer
dim M(0 to n-1) as integer
For i=0% to n-1 : m(i)=(i+1)*n : Next
=M()
}
? mult(4)
dim p(1 to 5) as long=500
group alfa {
dim p(1 to 5) as decimal=500 ' try currency, double, single
}
Print alfa.p(1)
z1->(alfa)
Print z1=>p(1)
for z1 {
for i=1 to 5: .p(i)*=.0005*i: next
}
z=group(z1)
Print z.p()
Print type$(z.p(1))
m=z.p()#REV()
Print m
m+=10
L=m#val(0)
Print type$(L)
Print type$(m)="mArray"
Print m#sum()
list
There are more to discuss about Version 12, but wait the new beta releases, or the first normal release (when all string/numeric functions checked).
Version 12 has enumarations using string also.
Enumeration Names {
a="hello"
b="hello two"
}
m=b
select case m
case a
? "is a"
case b
? " is b"
end select
? "done"
? m
Also now can be any numeric type (this is Decimal type to be used as 64bit unsigned Integer - from literal):
enum alfa {
onebig=0xFFFF_FFFF_FFFF_FFF0
otherBig=0x7FFF_FFFF_FFFF_FFFF
}
list