About arrays

Ideas for improvement
Post Reply
User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

About arrays

Post by Dutchman » Thu Oct 03, 2019 5:21 pm

After cooling down from my frustration on viewtopic.php?f=5&p=311#p310

:arrow: Could the function SIZE OF be extended according to the following description:
SIZE OF m
Returns the number of elements in the list or dictionary M.
If M is an array initiated with DIM M(n), then the function returns the highest index n. The total size is then dependent on the setting of OPTION BASE.
.
:arrow: The following section of the chapter "Arrays" is at the end of the chapter, after the section where the dictionary is explained.
By default the first element in an array has index 0. But it is possible to address the first element using index 1. This is done by using the function OPTION BASE:
OPTION BASE 0 sets first element index to 0
OPTION BASE 1 sets first element index to 1
The following code:
DIM m() = 1 2 3 4 5
PRINT m(1); m(2); m(3); m(4)
OPTION BASE 1
PRINT m(1); m(2); m(3); m(4)
outputs:
2345
1234
As OPTION BASE setting affects the first index number, this also affects the total number of elements in an array. Compare these two examples:
OPTION BASE 0
DIM m(2 2) = 1 2 3 4 5 6 7 8 9
and
OPTION BASE 1
DIM m(2 2) = 1 2 3 4
.
Could that be moved to the end of the array-section, just before the start of the list section:
◇◇◇
List is a one-dimensional array with dynamic size and specific operations to manage its elements.
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: About arrays

Post by kibernetik » Thu Oct 03, 2019 6:08 pm

Ok. And what if array M is declared as DIM M(20,30,10)?
What value should be returned by the SIZE OF function?

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

Re: About arrays

Post by Dutchman » Fri Oct 04, 2019 8:41 am

kibernetik wrote:
Thu Oct 03, 2019 6:08 pm
Ok. And what if array M is declared as DIM M(20,30,10)?
What value should be returned by the SIZE OF function?
The major index, in this case 20
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: About arrays

Post by kibernetik » Fri Oct 04, 2019 9:29 am

Dutchman wrote:
Fri Oct 04, 2019 8:41 am
The major index, in this case 20
This is not a solution.
Because another user will ask why he can get the size of the 1st dimension and cannot get the size of the 2nd dimension.

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

Re: About arrays

Post by Dutchman » Fri Oct 04, 2019 5:23 pm

The user will know how the array is organized.
It is usually just the question how many entries the array has at the time of use. At least that is the dilemma that I am facing now.
I can also imagine that the return value is a list of all DIM(…) values if you consider it necessary.
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: About arrays

Post by kibernetik » Fri Oct 04, 2019 6:00 pm

There could be such a solution:

SIZE OF m[,n]
If M is a list or a dictionary then this function returns the number of elements in the list or dictionary M.
If M is an array then it is important if there is one or two arguments of the function. If there is only one argument then this function returns the dimension of the array M. If there are two arguments then this function returns the number of elements in the array M in its N-th dimension. N >= 1.

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

Re: About arrays

Post by Dutchman » Sat Oct 05, 2019 8:04 am

Oh, that would be perfect :idea:
It is still a long way to go

Post Reply