Example Program

PL/1 was a language developed by IBM in 1964 as NPL (New Programming Language). Renamed PL/1 in 1965, this language combines elements of ALGOL 60 (recursion and block-structure), Fortran IV (separate compilation with communication through global data), and COBOL 60 (data structures, input/output). Pointers were included as a data type and cross-sections of arrays could be referenced.

  1. /* PL/I PROGRAM EXAMPLE
  2. INPUT: AN INTEGER, LISTLEN, WHERE LISTLEN IS LESS THAN
  3. 100, FOLLOWED BY LISTLEN-INTEGER VALUES
  4. OUTPUT: THE NUMBER OF INPUT VALUES THAT ARE GREATER THAN
  5. THE AVERAGE OF ALL INPUT VALUES */
  6. PLIEX: PROCEDURE OPTIONS (MAIN);
  7. DECLARE INTLIST (1:99) FIXED.
  8. DECLARE (LISTLEN, COUNTER, SUM, AVERAGE, RESULT) FIXED;
  9. SUM = 0;
  10. RESULT = 0;
  11. GET LIST (LISTLEN);
  12. IF (LISTLEN > 0) & (LISTLEN < 100) THEN DO;
  13. /* READ INPUT DATA INTO AN ARRAY AND COMPUTE THE SUM */
  14. DO COUNTER = 1 TO LISTLEN;
  15. GET LIST (INTLIST (COUNTER));
  16. SUM = SUM + INTLIST (COUNTER);
  17. END;
  18. /* COMPUTE THE AVERAGE */
  19. AVERAGE = SUM / LISTLEN;
  20. /* COUNT THE NUMBER OF VALUES THAT ARE > AVERAGE */
  21. DO COUNTER = 1 TO LISTLEN;
  22. IF INTLIST (COUNTER) > AVERAGE THEN
  23. RESULT = RESULT + 1;
  24. END;
  25. /* PRINT RESULT */
  26. PUT SKIP LIST ('THE NUMBER OF VALUES > AVERAGE IS:');
  27. PUT LIST (RESULT);
  28. END;
  29. ELSE
  30. PUT SKIP LIST ('ERROR—INPUT LIST LENGTH IS ILLEGAL');
  31. END PLIEX;


Readability Example

PL/1’s primary purpose/usage was to implement the “best qualities” of ALGOL 60, FORTRAN, and COBOL 60 for more generalized mainframe usage.

PL/1 main use has been on mainframes, however there are PL/I versions for DOS, Microsoft Windows, OS/2, AIX, OpenVMS, and Unix.

Readability

  • All variables are declared in same location.
  • Language implements a block structure.
  • Clear begin and end of functions.

  1. Bubble Sort
  2.  
  3. SHELL: PROCEDURE OPTIONS (MAIN);
  4. DECLARE
  5. ARRAY(50) FIXED BIN(15),
  6. (K,N) FIXED BIN(15);
  7.  
  8. GET LIST(N);
  9. GET EDIT((ARRAY(K) DO K = 1 TO N));
  10. PUT EDIT((ARRAY(K) DO K = 1 TO N));
  11. CALL BUBBLE(ARRAY,N);
  12.  
  13. END BUBBLE;
  14.  
  15. BUBBLE: PROCEDURE(ARRAY,N); /* BUBBLE SORT*/
  16. DECLARE (I,J) FIXED BIN(15);
  17. DECLARE S BIT(1); /* SWITCH */
  18. DECLARE Y FIXED BIN(15); /* TEMPO */
  19. DO I = N-1 BY -1 TO 1;
  20. S = '1'B;
  21. DO J = 1 TO I;
  22. IF X(J)>X(J+1) THEN DO;
  23. S = '0'B;
  24. Y = X(J);
  25. X(J) = X(J+1);
  26. X(J+1) = Y;
  27. END;
  28. END;
  29. IF S THEN RETURN;
  30. END;
  31. RETURN;
  32. END SRT;