Build your dream computer

Anything relating to non Sinclair computers from the 1980's, 90's or even before.
catmeows
Manic Miner
Posts: 716
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: Build your dream computer

Post by catmeows »

One of the issues with BASIC is the mess around IF statement.
Original BASIC had form IF condition THEN commands <EndOfLine>. False means "skip to next line" while true means continue execution (on same line). Indeed, it is very simple concept that can be implement easily.
Introducing ELSE increases complexity a lot, especially when ENDIF is ommited.

Different BASICs came with different solutions:
- introducing IF-ELSE-ENDIF with mandatory ENDIF
- single line IF-THEN with optional ELSE and only one IF is allowed on line
- single line IF-THEN with optional ELSE. Multiple IFs Are allowed and single ELSE branch is taken as alternative for any failed IF
- single line IF-THEN with optional ELSE. Multiple IFs are allowed and single ELSE is alternative for the last IF.
- single line IF-THEN with optional ELSE. Multiple IFs are allowed and multiple ELSEs are allowed. Interpret tries to figure out what ELSE is counterpart to what IF. This task can be solved with assumption that every IF has ELSE or there Is no ELSE on line at all.

Some BASICs allowed both single line IF-THEN and multiline IF-THEN-ELSE-ENDIF, considering line with IF-THEN without any following command as start of multiline IF-THEN-ELSE-ENDIF.
That somehow works but it is mess.

IMHO the original single line IF-THEN has its beauty in context of line oriented BASIC. When BASIC wants use both single and multiline IFs, it should probably solve it with different syntax. For example IF-THEN for single line and IF-BEGIN-ENDIF for multiline statement. It is not accident Pascal uses BEGIN-END for coumpound statements, it makes life easier.

Another mess are procedures. There is concept of local variables, but results are returned in parameter passed as reference. Even if procedure could return result in proper way, without structures or records or objects, you sometimes need to return a tuple eg.

Code: Select all

LET x,y=PROC(a,b,c)
Last minor issue is with non counted loops. There is lot of variations on WHILE, REPEAT,UNTIL but they quite often lack way to exit loop or retrigger condition from any point inside loop i.e. BREAK/EXIT, CONTINUE.
Besides, DO statements WHILE (condition) statements REPEAT loop can mimic any of them and is cleaner, IMHO.
Proud owner of Didaktik M
User avatar
1024MAK
Bugaboo
Posts: 3118
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Build your dream computer

Post by 1024MAK »

Maybe, but the real problem here is that there appears to have been a vacuum with regards to the BASIC language being extended in a formal way. So each and every manufacturer added there own ‘extras’ in their own way...

Note that I am not saying that the extras should not have been included. Merely that if a formal enhanced standard had been developed, it would have been an incentive for manufacturers to use this standard for the core BASIC in their machines.

So the problem with the IF THEN ELSE ENDIF etc. and the REPEAT / DO / WHILE loops could have been sorted out.

In terms of returning values from procedures, that’s a little bit trickier. As it stands, the DEF FN is the structure that normally returns a value. If multiple values need to be returned, maybe a pointer to a variable structure is needed instead.

Myself, I normally use global variables for this job. Hence variables that I only required inside a procedure are LOCAL. Variables used for passing values from (or to) procedures are GLOBAL. I’ve written many programs using this method without any significant problems.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
Lethargeek
Manic Miner
Posts: 742
Joined: Wed Dec 11, 2019 6:47 am

Re: Build your dream computer

Post by Lethargeek »

the main problem of most (all?) home computer ROM BASIC versions is very poor code reusability
for bigger projects it's almost impossible to reuse even your own older code w/o lots of manual edits
(unless you're actually making many variants of the same project)
User avatar
1024MAK
Bugaboo
Posts: 3118
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Build your dream computer

Post by 1024MAK »

Not being able to reuse code without manual editing was not just a problem with BASIC though. It's the same with the ROM based FORTH that one home computer had. And the the simple filing system (in most home computers, just a simple cassette tape filing system) does not help. Couple that with the simple line editor...

And some BASICs at least did have MERGE available.

Having said that, given these limitations, people did write very complex programs.

What would have been most helpful would have been allowing you to specify a line number range in the SAVE command (does anyone know if any BASIC offered this?). Combined with a renumber command, this along with MERGE would have made routine reuse a lot easier.

These days, modern BASIC does not need line numbers and the code can be written and edited in text editors where you can copy, paste, cut and merge as much as you like.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
AndyC
Dynamite Dan
Posts: 1405
Joined: Mon Nov 13, 2017 5:12 am

Re: Build your dream computer

Post by AndyC »

I don't think BASIC on the CPC would let you save a specific block of lines, but it had bulk line deletion and renumbering commands. Also the MERGE and CHAIN MERGE commands had the ability to delete ranges of lines when loading in new code which could prevent remnants of old code getting mixed in if you weren't careful about line numbers (which was a problem with Sinclair's MERGE command).

But BASIC was never a standardised language and, I suspect, couldn't have been without detracting from making access to machine specific features more cumbersome. Microsoft tried to push for it with the whole MSX thing, but really that just created a slew of clone machines that struggled because they didn't have differentiating qualities.
catmeows
Manic Miner
Posts: 716
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: Build your dream computer

Post by catmeows »

Is it really a problem, considering your program had 1.5 kloc at most ?
Proud owner of Didaktik M
User avatar
Lethargeek
Manic Miner
Posts: 742
Joined: Wed Dec 11, 2019 6:47 am

Re: Build your dream computer

Post by Lethargeek »

1024MAK wrote: Sun Sep 20, 2020 6:28 am Not being able to reuse code without manual editing was not just a problem with BASIC though. It's the same with the ROM based FORTH that one home computer had. And the the simple filing system (in most home computers, just a simple cassette tape filing system) does not help. Couple that with the simple line editor...

And some BASICs at least did have MERGE available.
With FORTH when you load a block, a screen, or whatever it's called, you at least get some warnings on redefined words, and well written libraries were able to avoid such conflicts using vocabularies (not sure about the JA version, but even the most primitive ones i know were like this). And sometimes it was even ok to ignore it. With BASIC MERGE even if everything seems smooth you can only pray there weren't some hidden conflicts. To use MERGE properly first you need to read both sources thoroughly and usually edit one of them, sometimes both. Or carefully write one source from the start keeping in mind the probability of merging it with the other one(s).
1024MAK wrote: Sun Sep 20, 2020 6:28 am Having said that, given these limitations, people did write very complex programs.
and it was a royal pain
1024MAK wrote: Sun Sep 20, 2020 6:28 am What would have been most helpful would have been allowing you to specify a line number range in the SAVE command (does anyone know if any BASIC offered this?). Combined with a renumber command, this along with MERGE would have made routine reuse a lot easier.
this doesn't change much, you still need to read/edit sources thoroughly to be safe
User avatar
Joefish
Rick Dangerous
Posts: 2058
Joined: Tue Nov 14, 2017 10:26 am

Re: Build your dream computer

Post by Joefish »

I think my approach to IF THEN ELSE would be to count the number of IFs in the line up to the point one fails, then count that many ELSE statements back from the end of the line (or quit if there aren't enough). That way the first IF pairs with the last ELSE and so-on. Problem is it's twice the work to syntactically parse the whole line in reverse!
Post Reply