From
Basic
toSuperBASIC
VARIABLES
AND
NAMES
-
IDENTIFIERS
•
•
•
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 string: word$
sum
high_st$
total
day_of_week$
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.
Somefimes 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.
Super
BASIC
allows
integer variables which
take
only whole-number
values.
We
dlstin.9uish
INTEGER
VARIABLES
these with a percentage sign thus:
count%
number%
nearesLpound%
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
pri
ce
= 9
LET
cost
=
7.31
LET
countr.
=
13
But
If
you write:
LET
countX
=
5.43
the value of count% will become
5.
On the other hand:
LET
countX
=
5.73
will
cause the value of
counfOAJ
to
be
6.
You
can see that SuperBASIC does the best
it
can, rounding
off
to
the nearest whole number
The principle of
always
trying
to
be intelligently helpful, rather than give an error message
COERCION
or
do
something obviously unwanted,
is
carried further For example,
if
a string variable
mark$ has the value
164'
then:
LET
score
=
markS
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'
If
the string cannot be converted then
an
error
is
reported.
There
is
one other type of variable
in
SuperBASIC, or rather the SuperBASIC
system
makes
it
seem
so.
Consider the SuperBASIC statement:
IF
windy
THEN
fly_kite
In
other BASICs you might write:
IF
w=1
THEN
GOSUB
300
12/84
LOGICAL
VARIABLES
AND
SIMPLE
PROCEDURES
39