Microsoft Office Tutorials and References
In Depth Information
F.8 LISP
IDENTIFICATION DIVISION.
PROGRAM-ID. ADD02.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FIRST-NUMBER PIC IS 99.
01 SECOND-NUMBER PIC IS 99.
01 SUM PIC IS 999.
PROCEDURE DIVISION.
PROGRAM-BEGIN.
DISPLAY "ENTER FIRST NUMBER ".
ACCEPT FIRST-NUMBER.
DISPLAY "ENTER SECOND NUMBER ".
ACCEPT SECOND-NUMBER.
COMPUTE SUM = FIRST-NUMBER + SECOND-NUMBER
DISPLAY "THE SUM IS: " SUM.
PROGRAM-DONE.
STOP RUN.
In BASIC, the preceding program would be:
INPUT "Enter first number: ", n1
INPUT "Enter second number: ", n2
PRINT "The sum is: ", n1 + n2
This clearly points out the extreme verbosity of COBOL.
F.8 LISP
BASIC, C, Pascal, and FORTRAN are in many ways quite similar. Also, programs written in
these languages can be made quite readable, especially if the programmer intends to make it so.
There are other languages that seem not to be readable under any circumstances. For instance,
LISP was developed in the late 1950s by John McCarthy and Marvin Minsky at MIT, for the
purpose of doing list processing (hence the name) in connection with artificial intelligence
applications.
In LISP, everything is a list. Here is a sample:
; LISP sample program to define a predicate
; that takes two lists and returns the value
; T (for true) if the lists are equal and F otherwise
(DEFINE (
'(equal (LAMDBA (list1 list2)
(COND
((ATOM list1) (EQ list1 list2))
((ATOM list1 NIL)
((equal (CAR list1) (CAR list2))
 
Search JabSto ::




Custom Search