"ON k GOTO …" would be attractive

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

"ON k GOTO …" would be attractive

Post by Dutchman » Sun Nov 03, 2019 6:35 pm

ON k GOSUB or GOTO?
In the following code is a Load function that I will use in a lib under development.

Code: Select all

'Load data
'by Ton Nillesen, November 2019
'load a section of data from a list into a series of variables
'
DIM List()=(0,1,2,3,4,5,6,7,8,9)
p=4
a,b,c,d,e,f=LoadN|6(List,6,p)
PRINT "a =";a
PRINT "b =";b
PRINT "c =";c
PRINT "....."
PRINT "f =";f
END
'
DEF LoadN(a(),N,i)
' return N values from a() starting at index i
' 0<N<=10
IF N=1 THEN RETURN a(i)
IF N=2 THEN RETURN a(i) a(i+1)
IF N=3 THEN RETURN a(i) a(i+1) a(i+2)
IF N=4 THEN RETURN a(i) a(i+1) a(i+2) a(i+3)
IF N=5 THEN RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4)
IF N=6 THEN RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5)
IF N=7 THEN RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6)
IF N=8 THEN RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6) a(i+7)
IF N=9 THEN RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6) a(i+7) a(i+8)
IF N=10 THEN RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6) a(i+7) a(i+8) a(i+9)
END DEF
'
[this does not work
DEF LoadN(a(),N,i)
' return N values from a() starting at index i
' 0<N<=10
ON N GOTO 1,2,3,4,5,6,7,8,9
1: RETURN a(i)
2: RETURN a(i) a(i+1)
3: RETURN a(i) a(i+1) a(i+2)
4: RETURN a(i) a(i+1) a(i+2) a(i+3)
5: RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4)
6: RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5)
7: RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6)
8: RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6) a(i+7)
9: RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6) a(i+7) a(i+8)
10: RETURN a(i) a(i+1) a(i+2) a(i+3) a(i+4) a(i+5) a(i+6) a(i+7) a(i+8) a(i+9)
END DEF
]
At the end is an alternative in which I would like to use the "ON n GOTO ..." statement as a variant of the "ON n GOSUB ...".
"ON n GOSUB" does not work because then the RETURN values are not in the last RETURN statement.
Could the varianr "ON n GOTO ..." be added to the language?
It is still a long way to go

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

Re: "ON k GOTO …" would be attractive

Post by kibernetik » Sun Nov 03, 2019 6:37 pm

There is ON GOTO statement. Documentation, page 18.

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

Re: "ON k GOTO …" would be attractive

Post by Dutchman » Sun Nov 03, 2019 9:12 pm

Oops, I still had doc version 1.5
Thanks
It is still a long way to go

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

Re: "ON k GOTO …" would be attractive

Post by kibernetik » Sun Nov 03, 2019 9:29 pm

Yes, doc v1.5 is currently the latest version.
The ON GOTO statement is implemented from the very beginning, since version 1.0.

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

Re: "ON k GOTO …" would be attractive

Post by kibernetik » Mon Nov 04, 2019 2:05 pm

If I comment-out the first
DEF LoadN(a(),N,i)
and de-comment the second
DEF LoadN(a(),N,i)
then everything still works fine.

If you experience some difficulties with that code sample then please let me know.
On my side it works fine in both cases.

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

Re: "ON k GOTO …" would be attractive

Post by Dutchman » Wed Nov 06, 2019 8:51 am

kibernetik wrote:
Mon Nov 04, 2019 2:05 pm
On my side it works fine in both cases.
Yes, I discovered that too
I tested both versions in different programs. Something must have gone wrong there.
However, I can no longer reproduce it, the test programs have been deleted.
Sorry for the unnecessary time you took for this non-issue. :oops:
It is still a long way to go

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

Re: "ON k GOTO …" would be attractive

Post by kibernetik » Wed Nov 06, 2019 9:29 am

Nice that it works fine.
Please don't hesitate to report if something goes wrong.

Post Reply