Why did bbc basic not inspire named Gosubs in other Basics?

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Why did bbc basic not inspire named Gosubs in other Basics?

Post by B3_B3_B3 »

It seems puzzling to me that the beeb's BBC BASIC's named procedures (with parameters/local variables) did not inspire named Gosubs in its era's competing Basics (eg Cpc/ spectrum ): without the complication of parameters or locals surely a named gosub is a large improvement in readability for a small implementation outlay (and could be faster like Beeb procs)----

GOSUB screenClear is surely much nicer
Than GOSUB 401?
User avatar
danielj
Posts: 9904
Joined: Thu Oct 02, 2008 5:51 pm
Location: Manchester
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by danielj »

Without reading the minds of/asking anyone who wrote any of the other BASICs post BBC BASIC, I think you're never going to be able to answer that question.

(I also don't see any reason why anyone would use a named GOSUB in BBC BASIC, even though it was available, as you had PROC/DEFPROC)
paintings
Posts: 93
Joined: Mon Jul 13, 2020 7:41 pm
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by paintings »

As an aside, how would "named GOSUBs" work? I can think of two possible mechanisms:
  1. An additional statement type (e.g. LABEL label-name) is introduced to mark the start of a subroutine. The programmer can then use "GOSUB label-name".
  2. The destination is held in an ordinary BASIC variable (e.g. "screenClear=401").
Option 1 is an awkward-looking halfway house to using the full PROC mechanism.

Option 2 is rife with problems. For example, what happens if someone renumbers the program? Or if someone forgets that "screenClear" is being used as a GOSUB destination and accidentally uses it to store the result of an ordinary calculation? I know that "BASIC" and "robust" are not synonyms, but even so this looks like a recipe for disaster.
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by B3_B3_B3 »

paintings wrote: Tue Apr 30, 2024 1:03 pm As an aside, how would "named GOSUBs" work?
....
I meant the language itself to implement it internally so I meant implemented similarly to beeb procs (so search and cache sub addresses, so it gains a speed advantage) but without the complexity of supporting parameters/arguments: thus I would expect such GOSUBS to be simple enough for a person capable of writing an interpreter.

Line renumbering is not a problem as the interpreter deals with searching for and caching the sub definition body.

One could do GOSUB .<label> with a new token for the pair to save mem/gain speed; and either a new DEFSUB keyword could be used and/or again just a preceding decimal point* before the Subroutine entry label just like assembly labels.

*or other punctuation the dec point was inspired by assembler labels.
User avatar
jgharston
Posts: 5332
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by jgharston »

Loads of my Spectrum Basic programs are full of stuff like:
LET CON=1000:LET COFF=1010:LET CSET=1020
....
GOSUB CON:GOSUB CSET:GOSUB COFF
...
etc.
1000 blah blah blah:RETURN
1010 blah blah blah:RETURN
1020 blah blah blah:RETURN
etc.

eg link.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
dr_d_gee
Posts: 30
Joined: Thu Feb 01, 2024 6:53 pm
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by dr_d_gee »

Microsoft-style Basics generally didn't allow variables to be used in GOTO, GODUB and RESTORE statements, and some other BASICs followed this lead — Locomotive Basic in the Amstrad CPCs. The short-lived Amiga BASIC from Microsoft did have named GOSUBs etc and didn't have line numbers IIRC. Later QuickBASIC and its descendants had named subroutines and functions.
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by B3_B3_B3 »

jgharston wrote: Tue Apr 30, 2024 2:59 pm Loads of my Spectrum Basic programs are full of stuff like:
LET CON=1000:LET COFF=1010:LET CSET=1020
....
GOSUB CON:GOSUB CSET:GOSUB COFF
...
It would be nicer if it was built into the language though ....

(Also the spectrum doesnt seem to have a renumber command which suits your method)..
julie_m
Posts: 594
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by julie_m »

B3_B3_B3 wrote: Tue Apr 30, 2024 11:51 am It seems puzzling to me that the beeb's BBC BASIC's named procedures (with parameters/local variables) did not inspire named Gosubs in its era's competing Basics (eg Cpc/ spectrum ): without the complication of parameters or locals surely a named gosub is a large improvement in readability for a small implementation outlay (and could be faster like Beeb procs)----

GOSUB screenClear is surely much nicer
Than GOSUB 401?
Spectrum (and ZX81) BASIC had exactly that feature; its GOTO and GOSUB statements (and RESTORE, on the Spectrum) would accept any expression that resolved to a number. Meaning you could do things such as GOSUB 1000+1000*INT(RND*6) if you really wanted. But it was more useful in constructions like GOSUB menu or GOTO mainloop. And unlike BBC BASIC, Sinclair BASIC would accept a non-existent line number as a GOTO or GOSUB target (carrying on from the next line afterwards). I haven't doven deeply enough into the ROM code to know for sure, but I'd guess someone was using JR C as opposed to JR Z when searching for the target line.
B3_B3_B3
Posts: 404
Joined: Sat Apr 08, 2017 10:42 pm
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by B3_B3_B3 »

julie_m wrote: Tue Apr 30, 2024 4:04 pm....
Spectrum (and ZX81) BASIC had exactly that feature; its GOTO and GOSUB statements (and RESTORE, on the Spectrum) would accept any expression that resolved to a number. Meaning you could do things such as GOSUB 1000+1000*INT(RND*6) if you really wanted. But it was more useful in constructions like GOSUB menu]. ...
The above tricks would be scuppered by a renumber command?
I had hoped my original post was clear that I meant the Renumber-proof bbc procedure/function name style of storing the name against an address in a list which is also faster after eachs' 1st call (unless some preprocessing is done but that is a separate post :) )
User avatar
danielj
Posts: 9904
Joined: Thu Oct 02, 2008 5:51 pm
Location: Manchester
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by danielj »

B3_B3_B3 wrote: Tue Apr 30, 2024 4:27 pm The above tricks would be scuppered by a renumber command?
I had hoped my original post was clear that I meant the Renumber-proof bbc procedure/function name style of storing the name against an address in a list which is also faster after eachs' 1st call (unless some preprocessing is done but that is a separate post :) )
No renumber command in spectrum/ZX81 BASIC.
User avatar
1024MAK
Posts: 12793
Joined: Mon Apr 18, 2011 5:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by 1024MAK »

For the ZX Spectrum, there was no renumber command until the introduction of the 128 model.

What you are really asking is why manufacturers of machines using BASIC did not include labels as an option in the code. Then GOTO label or GOSUB label would have been possible.

Psion did include labels in their BASIC like OPL.

I suspect the main reason was a combination of wanting the provided BASIC to be to the minimum of what was then recognised as "standard" BASIC, cost and available ROM space. With other "more exciting" features taking priority (graphic and sound commands/functions as some examples).

Mark
User avatar
roland
Posts: 5149
Joined: Thu Aug 29, 2013 9:29 pm
Location: Born (NL)
Contact:

Re: Why did bbc basic not inspire named Gosubs in other Basics?

Post by roland »

The Atom Basic has labels for GOTO and GOSUB, albeit a single letter :mrgreen:

Code: Select all

10 GOSUB c
20 PRINT "TEXT ON AN EMPTY SCREEN"'
30 END
40 
50cPRINT $12
60 RETURN
This is quite fast because the address of the label is stored at a fixed position in the Basic workspace memory. So the interpreter doesn't need to search for a line number every time a GOSUB or GOTO is used. Line numbers are still allowed.
FPGAtom: 512 KB RAM, Real Time Clock and 64 colours
MAN WOMAN :shock:
Post Reply

Return to “programming”