Sinclair QL Beginner's Manual page 47

Hide thumbs Also See for QL:
Table of Contents

Advertisement

Most BASICs have numeric and string variables. As in other BASICs the distinguishing feature of a
string variable name in SuperBASIC is the dollar sign on the end. Thus:
numeric:
count
sum
total
You may not have met such meaningful variable names before though some of the more recent
BASICs do allow them. The rules for identifiers in SuperBASIC are given in the Concept Reference
Guide. The maximum length of an identifier is 255 characters. Your choice of identifiers is a personal
one. Sometimes the longer ones are more helpful in conveying to the human reader what a program
should do. But they have to be typed and, as in ordinary English, spade is more sensible than
horticultural earth-turning implement. Shorter words are preferred if they convey the meaning but very
short words or single letters should be used sparingly. Variable names like X, Z, P3, Q2 introduce a
level of abstraction which most people find unhelpful.
INTEGER VARIABLES
SuperBASIC allows integer variables which take only whole-number values. We distinguish these
with a percentage sign thus:
count%
number%
nearest_pound%
There are now two kinds of numeric variable. We call the other type, which can take whole or
fractional values, floating point. Thus you can write:
LET price = 9
LET cost = 7.31
LET count% = 13
But if you write:
LET count% = 5.43
the value of count% will become 5. On the other hand:
LET count% = 5.73
will cause the value of count% to be 6. You can see that SuperBASIC does the best it can, rounding
off to the nearest whole number.
COERCION
The principle of always trying to be intelligently helpful,rather than give an error message or do
something obviously unwanted, is carried further. For example, if a string variable mark$ has the
value
'64'
then:
LET score = mark$
will produce a numeric value of 64 for score. Other versions of BASIC would be likely to halt and say
something like:
'Type mis-match'
or 'Nonsense in BASIC'
string:
word$
high_st$
day_of_week$

Advertisement

Table of Contents
loading

Table of Contents