Page 1 of 1
Spectrum Basic Variables
Posted: Sat Aug 11, 2018 10:01 am
by derek
Hi,
I have been reading some Spectrum Basic programming books, I was wondering if a variable can have the same name as an array, i.e.
LET score=0
and
DIM score(50)
Both seem to be allowed by the Spectrum Basic interpreter, but clearly bad programming practise to have an array the same name as a variable.
Re: Spectrum Basic Variables
Posted: Tue Sep 25, 2018 12:46 pm
by siggi
Re: Spectrum Basic Variables
Posted: Tue Sep 25, 2018 5:11 pm
by gregc
That is quite common to BASIC interpreters. Variables are saved on different stacks and any checking is on that stack so you can sometimes have A (float), A% (integer), A(..) (array) and A$ (string). Yes, confusing, but it is best practice to use longer variable names anyway if possible (not always easy in 16K and impossible in 1K). On the BBC Micro, variable A to Z (float) and A% to Z% (integer) were actually at fixed addresses so referencing them was incredibly fast.
Re: Spectrum Basic Variables
Posted: Tue Sep 25, 2018 9:47 pm
by 1024MAK
Yeah, keep in mind that on the ZX Spectrum the array name can only be a single letter.
Simple numeric variables with the same name can coexist with numeric array variables with the same name.
But you cannot have a simple string variable with the same name as a string array variable.
Also variable names are not case sensitive.
Mark