Spectrum Basic Variables

Post Reply
derek
Posts: 23
Joined: Fri Jan 23, 2015 11:31 am

Spectrum Basic Variables

Post 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.
Regards,

Derek
User avatar
siggi
Posts: 988
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Spectrum Basic Variables

Post by siggi »

Works also on ZX81:
ZX81.jpg
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
gregc
Posts: 5
Joined: Thu Aug 09, 2018 9:06 am

Re: Spectrum Basic Variables

Post 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.
User avatar
1024MAK
Posts: 5087
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Spectrum Basic Variables

Post 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
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply