## Presized array gives type mismatch with SIZE OF

Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Presized array gives type mismatch with SIZE OF

If you determine the maximum index of an array in a DIM statement eg DIM Test (5), then "SIZE OF" gives a "Type mismatch" for that array.
If you uncomment the commented part in the following code then the error occurs.

Code: Select all

``````'Size of array in user function
DIM Test1()=0,1,2,3 ' no parameter for highest index
PRINT "Size =";Asize(test1)
n=5
DIM Test2(n)=0,1,2,3,4,5 ' parameter n for highest index
PRINT Test2(n)
[ uncommented this gives Type mismatch
nn=SIZE OF Test2
PRINT "nn=";nn
PRINT "Size Test2=";Asize(test2)
]
END
'
DEF Asize(x())
n=SIZE OF x
RETURN n
END DEF
``````
It is still a long way to go

kibernetik
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

### Re: Presized array gives type mismatch with SIZE OF

Function SIZE OF returns the size of a list or a dictionary (a variable-sized array). It does not return a size of a fixed-sized array.

Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Re: Presized array gives type mismatch with SIZE OF

Oh that's very annoying and confusing.
• How can I find out the "OPTION BASE" applied?
• How can I know the highest index?
It is still a long way to go

kibernetik
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

### Re: Presized array gives type mismatch with SIZE OF

Dutchman wrote:
Mon Sep 30, 2019 9:19 am
• How can I find out the "OPTION BASE" applied?

Code: Select all

``````OPTION BASE 1
PRINT OPTION BASE
OPTION BASE 0
PRINT OPTION BASE
``````
Dutchman wrote:
Mon Sep 30, 2019 9:19 am
• How can I know the highest index?
You set it yourself when you declare the array.
Dutchman wrote:
Mon Sep 30, 2019 9:19 am
Oh that's very annoying and confusing.
BestBASIC has arrays with fixed size and lists with arbitrary size. These are very different objects.
Function SIZE OF returns the current size of a list or dictionary of unknown size, because some functions return them as a result of some operations and user does not know their size.
The size of an array with a fixed size is always known to the user, because he set it himself. He can keep these values if he needs them.

Array always have its fixed size declaration:

Code: Select all

``DIM X(20,20)``
List, on the contrary, never has size declaration because its size is variable and it is created as an empty object with zero size:

Code: Select all

``DIM Y()``
These are different objects and they have different functionality, although they have one thing in common - they can be addressed using an index:

Code: Select all

``````A = X(5)
B = Y(5)``````
Lists have their own special commands to operate, these commands cannot be used with arrays or dictionaries, for example:

Code: Select all

``````DIM Y()
Y + 20
PRINT Y(0)``````
Dictionaries also have their own functionality, different from arrays and lists.
Please refer to the manual for more details.

So, do not confuse between the usage of arrays, lists and dictionaries, although their declaration is made using the same DIM statement.

Moreover, fixed-size arrays can be multi-dimensional, so the question of their "size" is more complex, including the question of how much dimensions does an array have and what are the sizes in each of its dimensions.
Lists and dictionaries cannot be multi-dimensional, so their size is always single number.

Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Re: Presized array gives type mismatch with SIZE OF

That is a lot of bullshit to say:
"No in BestBASIC you cannot request the size of an array"
I'm so tired of this.
I am re-translating my DSP librabry to BestBASIC and some functions need that info. Of course I can add a parameter, don't teach me that now either.
Would you please show some understanding for my requests. I don't nag, but only present real problems and really try to help BestBASIC move forward.
It is still a long way to go

kibernetik
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

### Re: Presized array gives type mismatch with SIZE OF

Dutchman wrote:
Mon Sep 30, 2019 3:16 pm
That is a lot of bullshit to say:
"No in BestBASIC you cannot request the size of an array"
I'm so tired of this.
I am re-translating my DSP librabry to BestBASIC and some functions need that info. Of course I can add a parameter, don't teach me that now either.
Would you please show some understanding for my requests. I don't nag, but only present real problems and really try to help BestBASIC move forward.
Please keep your emotions within yourself. The only manner allowed here is a polite form. This is a warning.