Is GOTO / GOSUB x still BASIC?

This forum is dedicated to those who wish to suggest new features.
Questo forum è dedicato a chi desidera suggerire nuove feature.
Ce forum est dédié à ceux qui souhaitent suggérer de nouvelles fonctionnalités.
Post Reply
spotlessmind1975
Site Admin
Posts: 163
Joined: Fri Oct 06, 2023 8:25 pm

Is GOTO / GOSUB x still BASIC?

Post by spotlessmind1975 »

[italian and french follows]

:arrow: english

Hi everyone!

Recently, I implemented a mechanism for dynamic RESTORE. In short, instead of using a label or a line number, you can use a variable (provided it is defined and valued) to indicate (yes!) the line number from which to start reading the data.This is a very convenient mechanism for implementing even complex data structures, without occupying RAM memory with useless copies, because the data entered with DATA are "read only".

Reading on a BASIC group, I discovered that some dialects implement similar syntax for the GOTO and GOSUB commands. Basically, you can write a program like this and watch it work.

Code: Select all

100 x = 300
200 GOTO x
250 END
300 PRINT "x = 300"
My question is: is it still BASIC? And if it is, how should it behave in certain extreme conditions? For example, what should you do if the variable indicates a line number that doesn't exist?

Small spoiler: in RESTORE the pointer is placed at the end of the data, so you will get a nice TRUE on READ END().

:arrow: italian

ciao a tutti!

Recentemente, ho implementato un meccanismo per il RESTORE dinamico. In estrema sintesi, invece di usare una etichetta o un numero di linea, potete usare una variabile (purché definita e valorizzata) per indicare (questo sì!) il numerodi linea da cui partire a leggere i dati. Si tratta di un meccanimo molto comodo per implementare strutture dati anche complesse, senza per questo occupare memoria RAM con copie inutili, perché i dati inseriti con DATA sono "a sola lettura".

Leggendo su un gruppo BASIC, ho scoperto che alcuni dialetti implementano una sintassi simile per i comandi GOTO e GOSUB. In pratica, potete scrivere un programma come questo e vederlo funzionare.

Code: Select all

100 x = 300
200 GOTO x
250 END
300 PRINT "x = 300"
La mia domanda è: è ancora BASIC? E se lo è, come si deve comportare in certe condizioni estreme? Ad esempio, cosa dovrebbe fare se la variabile indica un numero di linea che non esiste?

Piccolo spoiler: in RESTORE il puntatore viene posto alla fine dei dati, quindi otterrete un bel TRUE su READ END().

:arrow: french

Salut tout le monde!

Récemment, j'ai implémenté un mécanisme de RESTORE dynamique. Bref, au lieu d'utiliser un label ou un numéro de ligne, vous pouvez utiliser une variable (à condition qu'elle soit définie et valorisée) pour indiquer (oui !) le numéro de ligne à partir duquel commencer la lecture des données. Il s'agit d'un mécanisme très pratique pour implémenter des structures de données même complexes, sans occuper la mémoire RAM avec des copies inutiles, car les données saisies avec DATA sont "en lecture seule".

En lisant sur un groupe BASIC, j'ai découvert que certains dialectes implémentent une syntaxe similaire pour les commandes GOTO et GOSUB. Fondamentalement, vous pouvez écrire un programme comme celui-ci et le regarder fonctionner.

Code: Select all

100 x = 300
200 GOTO x
250 END
300 PRINT "x = 300"
Ma question est : est-ce toujours BASIC ? Et si tel est le cas, comment doit-il se comporter dans certaines conditions extrêmes ? Par exemple, que faire si la variable indique un numéro de ligne qui n'existe pas ?

Petit spoiler : dans RESTORE le pointeur est placé à la fin des données, vous obtiendrez donc un joli TRUE sur READ END().
ldir_hector
Posts: 12
Joined: Sun Oct 08, 2023 11:47 am

Re: Is GOTO / GOSUB x still BASIC?

Post by ldir_hector »

On the Amstrad CPC standard basic, the only way to jump on a line number contained in a variable was by the CHAIN MERGE "prog.bas",lineNumber% method.
And if the line didn't exist, the program was loaded but the interpreter gives an error : "Line does not exist" and the program won't be executed.
spotlessmind1975
Site Admin
Posts: 163
Joined: Fri Oct 06, 2023 8:25 pm

Re: Is GOTO / GOSUB x still BASIC?

Post by spotlessmind1975 »

Hi ldir_hector, thank you for the message and... well, program chaining... my forbidden dream! 8-)
ldir_hector wrote: Tue Nov 21, 2023 8:45 pm On the Amstrad CPC standard basic, the only way to jump on a line number contained in a variable was by the CHAIN MERGE "prog.bas",lineNumber% method.
This is quite interesting. In the sense that the complexity to carry out this task seems to me the same as a GOTO x... who knows why they didn't expand it to the unconditional jump too?
ldir_hector wrote: Tue Nov 21, 2023 8:45 pm And if the line didn't exist, the program was loaded but the interpreter gives an error : "Line does not exist" and the program won't be executed.
Ok, actually I have one more difficulty: I can't interrupt execution by showing an error. So I would use a defensive technique: if a condition isn't there, I continue as if nothing had happened. For example, there is the ON ... GOTO statement which, if it doesn't have enough parameters on the right to match the value of the variable, doesn't jump. Or the RESTORE which places the pointer to the DATA at the end if it does not find the line number. And so on.
User avatar
wysardry
Posts: 26
Joined: Sun Oct 08, 2023 6:45 pm

Re: Is GOTO / GOSUB x still BASIC?

Post by wysardry »

I don't remember using an 8-bit machine that would allow you to use a variable as a line number for GOTO or GOSUB.

SELECT CASE statements or ON x GOTO/GOSUB would work instead in most situations.
spotlessmind1975
Site Admin
Posts: 163
Joined: Fri Oct 06, 2023 8:25 pm

Re: Is GOTO / GOSUB x still BASIC?

Post by spotlessmind1975 »

wysardry wrote: Wed Nov 22, 2023 6:45 pm I don't remember using an 8-bit machine that would allow you to use a variable as a line number for GOTO or GOSUB.
AFAIK, it is possible on some dialects, like BBC BASIC.
wysardry wrote: Wed Nov 22, 2023 6:45 pm SELECT CASE statements or ON x GOTO/GOSUB would work instead in most situations.
Yeah, but it is more verbose.
Post Reply