OPTION BASE 1
- Fernando Perez
- Posts: 378
- Joined: Mon Feb 15, 2021 10:09 pm
- Location: Santander (Spain)
- Has thanked: 195 times
- Been thanked: 267 times
OPTION BASE 1
Would it be complicated or dangerous to incorporate into your programming language the OPTION BASE 1 statement for handling arrays?
Thank you.
Thank you.
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1360 times
- Contact:
Re: OPTION BASE 1
Should not be hard but I cannot see the benefit of this function.
Basically it should trigger an error if the index goes to 0.
What is the goal for you ?
Basically it should trigger an error if the index goes to 0.
What is the goal for you ?
- Fernando Perez
- Posts: 378
- Joined: Mon Feb 15, 2021 10:09 pm
- Location: Santander (Spain)
- Has thanked: 195 times
- Been thanked: 267 times
Re: OPTION BASE 1
It is a very personal opinion, but I think that the natural way of counting for human beings is 1, 2, 3 .. etc.
Throughout my years of programming, when using arrays, I have always found it annoying to have to subtract one from the result of my functions to correctly address an array and it is something that leads to errors and requires additional lines of code.
But it was just an idea to improve Annex.
Throughout my years of programming, when using arrays, I have always found it annoying to have to subtract one from the result of my functions to correctly address an array and it is something that leads to errors and requires additional lines of code.
But it was just an idea to improve Annex.
-
- Posts: 143
- Joined: Mon Feb 08, 2021 10:10 pm
- Location: Scotland
- Has thanked: 47 times
- Been thanked: 51 times
Re: OPTION BASE 1
No - it's not just you - me too Always adding or subtracting 1 and sometimes forgetting...
A quick reminder from my bookshelf showed that every version of Microsoft Basic (and VBA) has included that option. Although in later versions they preferred you to use the "to" word eg DIM V(1 to 10).
A quick reminder from my bookshelf showed that every version of Microsoft Basic (and VBA) has included that option. Although in later versions they preferred you to use the "to" word eg DIM V(1 to 10).
You do not have the required permissions to view the files attached to this post.
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1360 times
- Contact:
Re: OPTION BASE 1
It is still not clear for me what can add this feature.
Nothing inhibit you to use the Arrays starting from 1; this option should just warn an error is the index 0 is used.
Nothing inhibit you to use the Arrays starting from 1; this option should just warn an error is the index 0 is used.
- Fernando Perez
- Posts: 378
- Joined: Mon Feb 15, 2021 10:09 pm
- Location: Santander (Spain)
- Has thanked: 195 times
- Been thanked: 267 times
Re: OPTION BASE 1
Yes, it can be an option. Work by forgetting that element 0 of the array exists and never accessing it. Just remember, when filling in the matrix, that we must start with element 1.
Example, dim array$(8) = "", "Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"
And remember when sizing that we must always have our number of elements plus one.
Example, dim array$(8) = "", "Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"
And remember when sizing that we must always have our number of elements plus one.
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1360 times
- Contact:
Re: OPTION BASE 1
I see, but I think that this is the only case where it could be of some use.
Do you see other cases where it could have an effect?
P.S.
The sizing is always dimensioned to include the last element, i.e. dim a(10) works from a(0) to a(10).
[Local Link Removed for Guests]
Do you see other cases where it could have an effect?
P.S.
The sizing is always dimensioned to include the last element, i.e. dim a(10) works from a(0) to a(10).
[Local Link Removed for Guests]
- Electroguard
- Posts: 860
- Joined: Mon Feb 08, 2021 6:22 pm
- Has thanked: 276 times
- Been thanked: 323 times
Re: OPTION BASE 1
Just to re-emphasise a point which some may have missed...
Annex DIM(n) actually already gives the best of both worlds by default, cos it can either be used to reference elements from 1 to n (simply by ignoring element 0), or it can be used to reference elements from 0 to n-1 (simply by ignoring element n, eg for neopixels).
Annex DIM(n) actually already gives the best of both worlds by default, cos it can either be used to reference elements from 1 to n (simply by ignoring element 0), or it can be used to reference elements from 0 to n-1 (simply by ignoring element n, eg for neopixels).
-
- Posts: 143
- Joined: Mon Feb 08, 2021 10:10 pm
- Location: Scotland
- Has thanked: 47 times
- Been thanked: 51 times
Re: OPTION BASE 1
Ok - I know about + and -1. But sometimes it just seems silly.
A$="The quick brown fox jumps over the lazy dog"
Everyone can see that the 4th word is fox.
Even Annex gives "fox" for WORD$(A$, 4) .
Now stick the words into an array and the +-1 rears it's ugly head.
A$="The quick brown fox jumps over the lazy dog"
Everyone can see that the 4th word is fox.
Even Annex gives "fox" for WORD$(A$, 4) .
Now stick the words into an array and the +-1 rears it's ugly head.
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1360 times
- Contact:
Re: OPTION BASE 1
Sorry but it is still not clear for me.[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed Jul 12, 2023 5:25 pm Ok - I know about + and -1. But sometimes it just seems silly.
A$="The quick brown fox jumps over the lazy dog"
Everyone can see that the 4th word is fox.
Even Annex gives "fox" for WORD$(A$, 4) .
Now stick the words into an array and the +-1 rears it's ugly head.
What inhibit you to put the result into an array ?