• Welcome to Jose's Read Only Forum 2023.
 

O2 Arrays / BASIC Standardization

Started by Eduardo Jorge, September 03, 2022, 11:14:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nicola_Piano

Well said Theo,
it's also useful when passing in an array the splitting of a string by a field separator character...
I have often used these commands.

I really appreciate what Charles is doing. :)
I'd like to have descriptions of the commands/functions he's implementing so I can put them in the help.

Cheers

Zlatko Vid

QuoteI'd like to have descriptions of the commands/functions he's implementing so I can put them in the help

that would be nice Nicola...but require a lot of work ( i mean typing)

Charles Pegge

#62
This is a reiteration from the bottom of page 4 of this topic. But strider is new.

The latest 050P14 implements:

indexbase  0 or 1 as previous
#majorminor  row-major order
#minormajor  column-major order
dims  number of dimensions
elements  total number of elements
lbound  base elements (currently the same as indexbase)
ubound  max element for each dimension (adjusted with indexbase)
scaler  the multiplier used on each dimension to calculate the element location
strider  the th scaler multiplied by the size of each element

UPDATE:
https://github.com/Charles-Pegge/OxygenBasic/blob/master/OxygenBasic050P14.zip

testlog:

MULTIDIMENSIONS

'17/09/2022
'multidim check
uses console
'#minormajor
'dim int d(1,2,3,4,5)
'redim int d(1,2,3,4,5)
redim int d(5,4,3,2,1)
redim int d(10,10,10,10,10)
d(1,2,1,4,5)=123
print d(1,2,1,4,5) cr
'redim int d(1,2,3,4,5)
'redim int d(60,2)
int i
for i=1 to dims(d)
  print ubound(d,i) tab scaler(d,i) cr
next
print cr

int *dd=@d
'for i=1 to ubound(d)
'print i tab dd(i) cr
'pos 80 == 0*120+1*60+0*20+3*5+1*4+indexbase
'next
wait

/*
'16/10/2022
'elements, dims
'ubound, lbound
'arwd
int cc,ee
'#show "t.txt"{
dim int d(1,2,3,4,5)
'cc=elements(d)
'ee= dims(d)
'void_ hah,hah
'indexbase 0
cc=lbound(d)
ee=ubound(d)
'}
'
'#recordof swap
'#recordof scaler
'print cc "   " ee
int i=1
'print dims(d)
'print elements(d)
'
for i=1 to dims(d)
  print " " scaler(d,i)
  'print " " lbound(d,i)
  'print " " ubound(d,i)
next
print ubound(d) " ok"
*/


DIMS, SCALER AND STRIDER

'11/10/2022
'array traversal
'test strider
uses console
redim int x(1,3,4)
x={1,2,3,4,5,6,7,8,9,10,11,12}
int i
int k
int*j
@j=@x 'element pointer j
for i=1 to dims(x)
  print "scaler and strider "+str(i)+tab+scaler(x,i)+tab+strider(x,i)+cr
next
printl
k=strider(x,2)
printl "test strider 2: " k
printl
for i=1 to ubound(x,2)
   print "val " i ":" tab j cr
   @j+=k 'stride
next
wait


Nicola_Piano

Hi Charles.

Welcome P14.
O2 is growing!

Charles Pegge


I've also incorporated indexing into the core macros:

It is more useful to generate indexes than to sort the raw data directly.

reindex also supports filters.


'09/12/2022
'REINDEX TESTS
uses console
'indexbase 0
'int d={9,8,7,6,5,4,3,2,1,0}
'int d={8,9,6,7,4,5,2,3,0,1}
redim int d(100)
d={8,9,6,7,4,5,2,3,0,1}
redim int d(10)
int m=10
'
macro filter(r,i)
=================
if d[i]>=5
  r=1
endif
end macro
'
macro compare(r,i,j)
====================
'if d[i]>d[j] 'ascending
if d[i]<d[j] 'descending
  r=1
endif
end macro
'
reindex idx,m,n,filter,compare
'
'  idx     index to be created
'  m       count of data elements
'  n       count of resulting index
'  filter  filter macro
'  compare comparison macro
'
'PARTIAL USE OF REINDEX
'reindex idx,m,n,filter
'reindex idx,m,n,,compare
'reindex idx,m,n
'reindex idx,m : int n=m
'
'RESULTS
'=======
print "total " n cr cr
print "#"  tab "INDEX" tab "DATA" cr
int i,j
for i=indexbase to n+indexbase-1
  j=idx[i]
  print i tab j tab d[j] cr
next
print cr cr
del idx
wait

Charles Pegge

Quote
Assume that you get an ARRAY in a FUNCTION BYREF.
So how can you find out the dimensions of that ARRAY?
Yes, you can use L/UBOUND()
Theo

Yes. As long as dynamic arrays are passed double-pointered:


'PASSING WHOLE REDIMMED ARRAYS
'
uses console
redim double a(5,10,20,4)
'
sub ff(double *d[])
===================
print "Test attributes of a passed dynamic array" cr cr
int i
print "dims: " tab dims(d) cr
print cr
print "n" tab "lbound" tab "ubound" tab "scaler" tab "strider" cr
for i=1 to dims(d)
  print i tab lbound(d,1) tab ubound(d,i) tab scaler(d,i) tab strider(d,i) cr
next
end sub
'
'TEST:
ff a
wait
del a