EasyManuals Logo

Sinclair QL User Manual

Sinclair QL
422 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #105 background imageLoading...
Page #105 background image
•
The ultimate concept of a procedure
IS
that
It
should be a 'black box' which receives
speCific information from outside' and performs certain operations which may include
sending speCific Information back
to
the outside: The outside' may be the main program
or another procedure.
The term 'black box' Implies that
ItS
internal workings are not Important; you only think
about what goes
In
and what comes
out
It.
for example, a procedure uses a variable,
count. and changes
its
value, that might affect a variable of the same name
in
the main
program
Think of a mail order company
You
send them an order and cash; they send
you goods. Information
IS
sent
to
a procedure and
It
sends back action and/or new
Information.
Procedures
and
Functions
WHY
PROCEDURES?
•
Information
..........
-----
Action and/or
new information
Mail
Order
Company
Procedure
•
Goods
Order by cash
•
.........
-----
•
You
do
not want the mall order company
to
use your name and address or other
Information for other purposes. That would be an unwanted Side-effect Similarly you
do
not want a procedure
to
cause unplanned changes
to
values of variables used
in
the main program.
Of course you could make sure that there are no double uses of variable names
in
a
program. That will work up
to
a point but
we
have shown
in
this chapter how
to
avoid
trouble even
if
you forget what variables have been used
in
any particular procedure.
A second aim
In
uSing
procedures
IS
to
make a program modular. Rather than have
one long main program you can break the
JOb
down into what Seymour Papert, the
inventor of LOGO, calls 'MInd-Sized
bites:
These are the procedures, each one small
enough
to
understand and control
easily.
They are linked together by the procedure
calls
in
a sequence or hierarchy.
A third aim
IS
to
avoid writing the same code
tWice.
Write
It
once
as
a procedure and
call
it
tWice
If
necessary. Functions and procedures written tor one program can often
be directly used, Without change, by other programs, and one might create a library
of commonly used procedures and functions.
We
give below another example which shows how procedures make a program modular
An order
IS
placed for six dishes
at
Chan's
Take
Away,
where the menu
IS:
EXAMPLE
Item Number Dish
Price
1
2
3
Prawns
Chicken
SpeCial
3.50
280
3.30
Write procedures for the following
tasks.
1.
Set
up
two three-element arrays
shOWing
menu, dishes and prices. Use a
DATA
statement
2. Simulate
an
order for
SIX
randomly chosen dishes
uSing
a procedure, choose, and
make a tally of the number of times each dish
is
chosen.
12184
89
-

Other manuals for Sinclair QL

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair QL and is the answer not in the manual?

Sinclair QL Specifications

General IconGeneral
ProcessorMotorola 68008
Clock Speed7.5 MHz
RAM128 KB (expandable to 640 KB)
ROM48 KB
Operating SystemSinclair QDOS
Release Year1984
StorageMicrodrive tape loop
Graphics256x256 pixels, 8 colors
PortsRS-232, ROM cartridge
SoundBeeper (internal speaker)

Related product manuals