Languages and programs: basic, cobol and prolog
BASIC
Short for 'Beginners All-purpose Symbolic Instruction Code', BASIC was developed in the early 1960s at Dart mouth College in America as a simplified version of FOR TRAN, the intention being to produce a language for teaching the principles of programming. In the early days it was a simple language, with limited use outside education, but owing to its frugal memory requirements it was adopted as the main programming language for microcomputers. Many additional commands and structures were then added to extend the language's capabilities, each microcomputer manufacturer developing his own version of BASIC.
These extensions put BASIC on a par with FORTRAN for mathematical and scientific work. However, FORTRAN was designed in the days when computers were limited in power and expensive, and so an important requirement was that it carried out its tasks efficiently and in a way that made frugal demands on the computer's power. BASIC is not a particularly efficient language, but this hardly matters now that computing power is so cheap and plentiful. Ease of use and a short learning time are more important for people who are learning programming.
Besides being designed for beginners, BASIC was intended to be 'all-purpose'. Indeed, it can be used with almost any application, from performing scientific calculations to keeping business records and controlling devices such as robot arms. However, being a general-purpose language, it is not as good for specific applications as the more specialized languages such as FORTRAN and COBOL.
On page 94 there is a short program written in BASIC.
When run, it allows the user to input the unit price of a product, which it stores in memory under the variable PRICE, then input the quantity sold of the product, which it stores in memory under the variable QUANTITY. It then calculates the value of the sale and the total amount. It then calculates the VAT and displays the total. The program repeats this sequence endlessly until the user enters nothing as the price, i.e. simply presses the RETURN/ENTER key. It is quite easy to extend this program so that it produces proper invoices
COBOL
COBOL is an acronym for COmmon Business Oriented Language. It was developed in 1960, at the initiative of the US Defense Department, to provide a language that was efficient at file-handling and which could therefore be applied to business-oriented applications such as stock control. One of its earliest uses was the control of inventory on US warships.
With its file-handling capabilities, COBOL quickly established itself as the major language for processing business data, and it still retains this lead in organizations which use large computers.
A COBOL program consists of four divisions. These are:
• The identification division, which contains information for the users of the program, but which does not affect the processing of the data.
• The environment division, which specifies the hardware environment- i.e. the computer system and associated devices -in which the program will run.
• The data division, which specifies the files to be used, the type and size of data entries, and the computer storage required.
• The procedure division, which lists the operations that have to be performed by the computer to process the data, such as instructions to open files, to transfer data from those files to the computer's memory, to perform calculations, and to output results.
To illustrate these operations, here's a short extract from the procedure division of a COBOL program:
1 OPEN-FILES.
OPEN INPUT IN-FILE.
OPEN OUTPUT OUT-FILE.
2 SET-RECORDS.
MOVE SPACES TO OUT-REC.
MOVE 1 TO 0-RECORD-TYPE.
3 READ-FILE-IN.
READ IN-FILE AT END GO TO 5-FINISH. ADD 1TOWS-COUNT-IN.
MOVE IN-COPY TO OUT-COPY-1.
READ IN-FILE AT END GO TO 8-ABORT. ADD 1TOWS-COUNT-IN.
MOVE IN-COPY TO OUT-COPY-2.
PROLOG
Short for PROgramming in LOGic, this language is com monly used for programming expert systems (see Chapter 6). These are systems that store human experts' knowledge on particular subjects in the form of facts and rules, and allow non-experts to ask questions which draw on that knowledge.
A fact in PROLOG is an expression of the form 'A relates
to B'. Here are two examples of facts:
5 sum-of (3 2)
Lynda likes apples
A rule is a set of connected facts. Words that are used to connect facts include the logical operators AND, OR, and NOT, as well as the word IF. So a rule might be:
X likes pears if X likes apples
Using its store or knowledge base of facts and rules, the computer is able to deduce further facts. For example, if asked to list all people who like pears, it would include Lynda, using the fact that 'Lynda likes apples' and the rule 'X likes pears if X likes apples'.
Unlike the other languages I've mentioned, you cannot write a program in PROLOG. Its purpose is to allow you to add facts and rules to the knowledge base (using the command ADD), and to ask the computer to extract knowledge from that base in the form of inferences based on those facts and rules. To assist in this latter task, a number of query statements are available, namely state ments of the form 'is (A relates to B)'.
For example, if the facts earlier in this section have been entered into the computer, the query
Is (Lynda likes apples)
will receive from the computer the reply
Yes.
As is always the case with computers, the technology comes into its own where a large amount of data is involved. If a great many facts and rules about a subject have been entered into the computer, it is possible to extract useful knowledge which would otherwise remain hidden.
Comments
Post a Comment