home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / os2apipm.zip / PAPER.TXT next >
Text File  |  1996-11-09  |  31KB  |  717 lines

  1.                      Nonformal introduction to  ADA-95
  2.                            by Leonid  Dulman
  3.  
  4.         Since  ADA-95  may  become  the  base  programming  language  in 21
  5.     century, the question "How to teach ADA-95 ?" has top-priority.
  6.  
  7.         What principles must we follow teaching that programming language?
  8.  
  9.         1. The language must be studied  from "tabula rasa" , not referring
  10.     to other programming languages (including ADA-83);
  11.  
  12.         2.  We  have  to  avoid  referring  to  the  notions  that  will be
  13.     introduced later ;
  14.  
  15.         3. We have to use natural examples and clear analogies.
  16.  
  17.         ADA-95  is a  strong and   logically complete language. We  need to
  18.     understand  all its  base constructions.  Thus, its  study "online"  is
  19.     impossible.  We  must  come  back  to  the  earlier  introduced notions
  20.     permanently expanding their sphere.
  21.  
  22.         We study the  language by a spiral, the  new language constructions
  23.     are continuations of the earlier introduced ones.
  24.  
  25.         The  main question  for a  student (in  a study  process) is how to
  26.     solve his problems by means of the language implementations ?
  27.  
  28.         For a  teacher it is  very important to  show what problems  can be
  29.     solved by means of certain language constructions.
  30.  
  31.         You must remember that some problems  can not be solved by means of
  32.     ADA-95 clauses.There are procedures with variable number of parameters,
  33.     problems that have  a single realization (such as  explicit transfer of
  34.     control), and different realization problems (such as leaving a loop by
  35.     statements GOTO or EXIT).
  36.  
  37.         The top  important goals of training  are to connect the  aims of a
  38.     teacher and a  student, and to get accurate  answers for all questions.
  39.     This work  is an attempt to  give common ADA-95 descriptions  using the
  40.     above principles.
  41.  
  42.         Let  us  introduce  the  term  "PROGRAM"  as  some  entire language
  43.     construction which transforms the several  input data to require output
  44.     results.
  45.  
  46.                             ADA-95  program
  47.                       ┌───────────────────┐
  48.                      ^│     work data     │.
  49.                     . │   --------------- │ .
  50.                    . ^│      process 1    │  .
  51.                   . . └───────────────────┘   .
  52. ┌───────────────┐   . ^                        .
  53. │  common data  │ .  .┌───────────────────┐     .  ┌───────────────┐
  54. │protected data │....>│     work data     │      . │   results     │
  55. └───────────────┘ .. .│   --------------- │------->│   (output     │
  56. ┌───────────────┐ ... │      process 2    │      . │    data    )  │
  57. │     input     │.. . └───────────────────┘     .  └───────────────┘
  58. │     data      │.   .                         .
  59. └───────────────┘ .   V                       .
  60.                    .  ┌───────────────────┐  .
  61.                     . │    work data      │ .
  62.                      V│   --------------- │.
  63.                       │      process n    │
  64.                       └───────────────────┘
  65.         Input data  are transformed into  results by means  of one or  more
  66.     parallel execution processes.
  67.  
  68.         Thus  we manipulate  objects (data)  that must  be transformed  and
  69.     processes which execute these transformations.
  70.  
  71.         The objects used for the different means have different qualitative
  72.     characteristics.  The  qualitative  characteristic  of  the objects are
  73.     named TYPE.
  74.  
  75.         The object's type answers the question "What is it ?"
  76.  
  77.         What types of objects would we like to have in the language ?
  78.  
  79.         1.  Types  for  engineering   and  business  calculations  such  as
  80.     temperature or money (FLOAT and FIXED types);
  81.  
  82.         2.  Types  of  objects  for  numbering  other objects, for instance
  83.     quantity of books. There are INTEGER and MOD types ;
  84.  
  85.         3. The  types of objects for  working with words are  CHARACTER and
  86.     WIDE_CHARACTER;
  87.  
  88.         4. The types of TRUE/FALSE objects are BOOLEAN.
  89.  
  90.         The types described above are named PREDEFINED in the language.They
  91.     provide a base for new types or specifications named SUBTYPE.
  92.  
  93.         In ADA-95 the type is subtype for itself.
  94.  
  95.         But if you a composer and want  to write the notes, what do you do?
  96.     The  language creates  objects such  as  notes  or colors  by means  of
  97.     enumeration types.
  98.  
  99.         TYPE note is (C,D,E,F,G,A,H);
  100.  
  101.         The common types INTEGER,  MOD, BOOLEAN, CHARACTER, WIDE_CHARACTER,
  102.     are enumeration types.
  103.  
  104.         For example, TYPE BOOLEAN is (FALSE,TRUE).
  105.  
  106.         A objects can be created by means of the above types:
  107.  
  108.         VELOCITY : FLOAT;
  109.         MONEY : FIXED;
  110.         TYPE BYTE IS MOD 16#100#; -- one byte .
  111.         NUMBER : BYTE;
  112.  
  113.         We have the  magic word "NEW" to create a  new type having the same
  114.     "qualities" and with the same  internal structure as an already defined
  115.     type.
  116.  
  117.         TYPE MEAT IS NEW FLOAT;
  118.         TYPE BEEF IS NEW MEAT;
  119.  
  120.         But  how  can  we  describe  a  group  of homogeneous elements, for
  121.     instance text line? There is an  array construction in the language for
  122.     this purpose.
  123.  
  124.         TYPE STRING IS ARRAY(POSITIVE RANGE <>) OF CHARACTER;
  125.         TYPE WIDE_STRING IS ARRAY(POSITIVE RANGE <>) OF WIDE_CHARACTER;
  126.  
  127.         These  types  are  predefined  and  represent  unbounded  arrays. A
  128.     variable which determines element location is named index.
  129.  
  130.         An index has  a first and a last value.  Its range is defined using
  131.     the first and last values as range 3 .. 13 for instance.
  132.  
  133.         TYPE TABL IS ARRAY(1..10, -1..11) OF  FLOAT; is an example of a two
  134.     dimensional array of  float numbers with bounds in  the first direction
  135.     of (1, 10) and in the second direction of (-1,11).
  136.  
  137.         The index type is commonly INTEGER  or MOD but we have the question
  138.     "can we have  an array with week-days as the  index?". For example, the
  139.     array might store the usual working time for each day.
  140.  
  141.         The index may be of any enumeration type in ADA-95.
  142.  
  143.         TYPE WEEK IS (SN,MN,TU,WE,TH,FR,ST);
  144.         TYPE WORK_TIME IS ARRAY(WEEK) OF INTEGER;
  145.         TM : WORK_TIME := (0,8,8,8,8,6,0);
  146.  
  147.         Then TM(ST) for instance is equal to 0.
  148.  
  149.         Let us assume we want to collect information about a student in one
  150.     object.
  151.  
  152.         We  need  name  and  growth.  How  is  this  object described ? The
  153.     compound  type RECORD  may be  used somewhat  analogous to STRUCTURE in
  154.     other languages.
  155.  
  156.         The record includes of one or more element types .
  157.  
  158.         TYPE STUDENT IS RECORD
  159.                 NAME   : WIDE_STRING(1..24);
  160.                 GROWTH : FLOAT;
  161.         END RECORD;
  162.  
  163.         Notice that to  separate the record from other  statements we write
  164.     "END RECORD" after the record components.
  165.  
  166.         Let us remark  that a type contains is  the quality characteristics
  167.     of an object  and it answer the question  "what is it ?". But  often we
  168.     have to answer  the question "where is it  ?". How can we refer  to the
  169.     object? This may be done directly by name such as
  170.         LENGTH, WIDTH : INTEGER;   and then
  171.         WIDTH := 3;
  172.         LENGTH := width * 5;
  173.  
  174.         Alternatively,  we  often  desire  to  refer  to  an object via its
  175.     storage location  or address. The POINTER  terminology commonly used in
  176.     other  languages is  replaced in  ADA  by  the term  "ACCESS TYPE"  for
  177.     indirect location of or reference to objects.
  178.  
  179.         This  access type  object is  the address  for the object connected
  180.     with it.
  181.  
  182.         TYPE POINTER IS ACCESS STUDENT;
  183.  
  184.         Remark the important properties of the access types:
  185.  
  186.         1. An access type points to objects connected with it;
  187.  
  188.         2. The access type object can create recursive data (a list or tree
  189.     for instance). It can be a component of a record (node);
  190.  
  191.         3. If a type description contains the key word ALIASED, all objects
  192.     of this type may be called by reference.
  193.  
  194.         A simple example of an object and its pointer is follow:
  195.  
  196.         TYPE OBJECT_TYPE IS .........
  197.         TYPE POINT_TO_OBJECT_TYPE IS ACCESS ALL OBJECT_TYPE;
  198.         OBJECT          : ALIASED OBJECT_TYPE;
  199.         POINT_TO_OBJECT : POINT_TO_OBJECT_TYPE := OBJECT'ACCESS;
  200.  
  201.         Now we shall describe a transforming "process".
  202.  
  203.         The  process is  a set  of  the  language statements  which may  be
  204.     classified into groups:
  205.  
  206.         1. Assignment_statement is ":=";
  207.         2. Control statements are LOOP, IF, CASE, GOTO, SELECT;
  208.         3. Transform statements are subprogram calls.
  209.         4. The statement of an emergency situation is EXCEPTION.
  210.  
  211.         There  are two  forms of  subprogram :  procedures and functions. A
  212.     procedure call  is a statement; a  function call is an  expression  and
  213.     returns a value.
  214.  
  215.         Parameters are the objects that take part in transformations.
  216.         Procedures and functions may be used in recursive processes.
  217.         Inside the procedure or the function we can use others procedures and
  218.     functions.
  219.         Notice that subprogram parameters may be only objects and they must
  220.     have strongly defined types.
  221.  
  222.         If a function  has the parameters and the result  of the same type,
  223.     it  is  named  a  primitive  operation.  The  primitive  operations are
  224.     introduced to finish the recursive process. They are predefined for the
  225.     predefined types.
  226.  
  227.         For example functions "+","-","*","/","**", MOD, REM are predefined
  228.     for the INTEGER type.
  229.  
  230.         The notation I  := "+"(J,K) means that the integer  variable i is a
  231.     sum of the integers j and k.
  232.  
  233.         It  guarantees  the  checking  of  parameter  types  for  the given
  234.     subprogram. We can identify subprogram not only by the name, but by the
  235.     types or  the numbers of  parameters. This property  is named operation
  236.     compatibility.
  237.  
  238.         Let us have
  239.         I   : INTEGER;
  240.         S,R : CHARACTER; ,
  241.         then before the function
  242.                 R:="+"(S,I) can be used it must be defined since the normal
  243.     "+" function expects its two paramaters to be of the same type.
  244.          The function "+" with two parameters must be defined. The first is
  245.     the character and the second is the integer. And it returns the character
  246.     type.  This  function  has  nothing  common  with  the  function "+" in
  247.     statement I:="+"(J,K) where J and K are of the same type and where "+" is
  248.     predefined;
  249.  
  250.         Two questions arise regarding the subprogram conception:
  251.         1. Can we call or access a subprogram by way of its object address?;
  252.  
  253.         2. What can we do if a subprogram is the parameter of a subprogram?
  254.     For example, we want to calculate an integral of various functions.
  255.  
  256.         This problem may be solved by means of using access type objects as
  257.     parameters for subprograms.
  258.  
  259.         TYPE FUN_PTR IS ACCESS FUNCTION(X:FLOAT) RETURN FLOAT;
  260.         FUN, FUNSIN, FUNCOS : FUN_PTR;
  261.                 @@...........
  262.         FUNSIN := SIN'ACCESS; FUNCOS := COS'ACCESS; and so on.
  263.  
  264.         But if FUN  is an object, it may be  used as a subprogram parameter
  265.     for the integral calculation.
  266.  
  267.         Thus a subprogram  has parameters, but have can  we generalize this
  268.     very flexible mechanism  to types ? Can a type  depends on parameters ?
  269.     An array index  is the analogy of parameter,  but what do we do  for an
  270.     compound objects made up of several types? We use RECORDS.
  271.  
  272.         If a  parameter controls the internal  numeric characteristics of a
  273.     record, it's called a discriminant.
  274.  
  275.         For example
  276.              TYPE VARYING(MAXIMUM_LENGTH:INTEGER) IS RECORD
  277.              LEN : INTEGER RANGE 1..MAXIMUM_LENGTH;
  278.              CNT : STRING(1..MAXIMUM_LENGTH);
  279.              END RECORD;
  280.  
  281.         This record description allows creation of varying length strings
  282.     depending on the length given at string object creation.
  283.  
  284.     S1 : VARYING(100); S2:VARYING(255);
  285.  
  286.         But  the  parameters  can  also  be  used  for the record structure
  287.     control. The parameter is called a variant parameter.
  288.  
  289.         For example,
  290.           TYPE MOTOR IS (CAR,LORRY);
  291.           TYPE AUTO(MASH : MOTOR) IS RECORD
  292.            SPEED : FLOAT;
  293.            CASE MASH IS
  294.             WHEN CAR    => MEN : INTEGER;
  295.             WHEN LORRY  => WEIGHT : FLOAT;
  296.            END CASE;
  297.            END RECORD;
  298.         Thus  we  may  create  either  a  car  with  a  specific  number of
  299.     MEN (passengers) or a lorry with a specific WEIGHT.
  300.         It  is a  very comfortable  mechanism. You  can create objects that
  301.     have  many  common  properties,  but  with  some  difference  in  their
  302.     structure.
  303.  
  304.         However it is a static mechanism  and you have to examine the all
  305.     possible  variants.  But  if  you  design  a  large  program, it's very
  306.     difficult to see all possible requirements  at once and these types may
  307.     be very cumbersome.
  308.  
  309.         The language  allows creation of  the new types  dynamically. These
  310.     types inherit  the structure of  an earlier declared  type and add  new
  311.     necessary record components.
  312.  
  313.         They are called TAGGED records.
  314.  
  315.         TYPE FIGURE IS TAGGED RECORD
  316.                 NAME   : STRING(1..8);
  317.                 SQUARE : FLOAT;
  318.         END RECORD;
  319.  
  320.         Now we  can create additional  new types from  this parent type  as
  321.     needed by adding the necessary components. Let us note that all derived
  322.     types keep  the properties of  the tagged record.  These new types  are
  323.     able to be the prototype for other tagged types allowing a "tree" to be
  324.     created. This tree joins tagged types into the single term "CLASS".
  325.  
  326.         Since the class is introduced  dynamically, its subprograms must be
  327.     called in dynamically  too. This property of the  tagged types is named
  328.     dynamic  dispatch. In  this case  the type  controls the  choice of the
  329.     subprograms for operation compatibility.
  330.  
  331.        TYPE TRIANGLE IS NEW FIGURE WITH RECORD
  332.             L1,L2,L3:FLOAT;
  333.             END RECORD;
  334.  
  335.        TYPE RECTANGLE IS NEW TRIANGLE WITH RECORD
  336.             L4      :FLOAT;
  337.             END RECORD;
  338.  
  339.         The  record  unites  the  different  object  characteristics in one
  340.     structure  utilizing the  full logic  characteristic including  all the
  341.     parents. But  how can we unite  the different subprograms in  one logic
  342.     structure?
  343.  
  344.         For example, assume we need a group of i/o subprograms ?
  345.  
  346.         The  term PACKAGE  is introduced  into the  language to  create the
  347.     logic unit. It joins objects, types and subprograms.
  348.  
  349.         The   packages  have   specifications  in   which  types,  objects,
  350.     subprograms  and exceptions  are described.  If you  change the package
  351.     specification you must recompile all program units which utilize, with,
  352.     or reference the package.
  353.  
  354.         If the  package specification has subprogram(s),  the package has a
  355.     BODY with the code commonly in a different file from the SPECIFICATION.
  356.     The  body   includes  ada  source   code  for  the   execution  of  the
  357.     subprogram(s).  If the  package body  is changed  and is  in a separate
  358.     file, only  the BODY file needs  to be recompiled. This  provides large
  359.     development time savings for large programs with many separate files.
  360.  
  361.         The  package type-specifications may  be declared  as PRIVATE. It's
  362.     very  important that  all transformations  of objects  of private  data
  363.     types  be done  by means  of the  package subprograms  only. If  a type
  364.     is designated  as LIMITED PRIVATE we  can't compare two objects  of the
  365.     type except in the package-defined procedures.
  366.  
  367.         PACKAGE PASSWORD IS
  368.                 TYPE KEY IS LIMITED PRIVATE;
  369.                 FUNCTION CANCEL(KL:KEY) RETURN BOOLEAN;
  370.                 PRIVATE
  371.                         TYPE KEY IS STRING(1..8);
  372.         END PASSWORD;
  373.  
  374.         Packages have  may contain the  logical full system,  but there are
  375.     two difficulties:
  376.  
  377.         1. We  must recompile the entire  system If we want  to make even a
  378.     minor modification;
  379.         2. A package may be very large but you may need only a small subset.
  380.    It's the package SSP,for example .
  381.         How are these problems solved ?  We added new record components for
  382.     the tagged types  to create the related new child  types. By analogy we
  383.     have the parents-children mechanism for the packages. The types and the
  384.     primitive operations are introduced in  root level, and new subprograms
  385.     are described in the children packages.
  386.  
  387.         PACKAGE PASSWORD.CHANGE IS
  388.         PROCEDURE CHG(KL:KEY) ;
  389.         END PASSWORD.CHANGE;
  390.  
  391.         This mechanism  allows creation of  packages with smaller  size and
  392.     more logical complication.  Now we have solved almost  the all problems
  393.     of one  process program design .  But we must mention  the one "little"
  394.     problem.
  395.  
  396.         If we use  many types for input/output data,  we need many packages
  397.     (subprograms).  But  all  types  derived  from  one predefined type,use
  398.     equivalent operations. For  instance, in the FIGURE type  above, we may
  399.     need a  display function for  each parent and  child, SQUARE, TRIANGLE,
  400.     and RECTANGLE.
  401.  
  402.         In ADA-95 we have the subprograms with parameters, the records with
  403.     parameters, and it's naturally to ask  the question "can a package have
  404.     parameters ? "
  405.  
  406.         The  language  has  the  type  parametric  apparatus.  They are the
  407.     GENERIC procedures and packages.
  408.  
  409.         For example
  410.  
  411.             GENERIC TYPE REAL IS DIGITS <>;
  412.             PACKAGE IO IS
  413.                 PROCEDURE READ (X : OUT REAL);
  414.                 PROCEDURE WRITE(X : REAL);
  415.             END IO;
  416.  
  417.         When the IO  specification and body of the  package are compiled we
  418.     write
  419.  
  420.         WITH IO;
  421.                  ...............................
  422.         PACKAGE MEAT_IO IS NEW IO(MEAT);
  423.         PACKAGE VEAL_IO IS NEW IO(VEAL);
  424.         Z: MEAT;   Y: VEAL;
  425.  
  426.         Now  we  have  the  i/o   procedures  for  the  MEAT  meat.read(z),
  427.     meat.write(z)  and the  procedures veal.read(y),  veal.write(y) for the
  428.     veal .  It's needed to remark  that the bodies of  generic packages and
  429.     subprograms  would "with"  TEXT_IO and   we have  to use  the primitive
  430.     operations therein.
  431.  
  432.         But what  to do if  a system is  been designing ?  We approximately
  433.     know what  to do with data  but don't know the  data internal structure
  434.     and formation.  We want to connect  the process of planning  and design
  435.     with the process of programming.
  436.  
  437.         This  method  is  named  object-oriented  programming  (OOP) and is
  438.     realized in ADA-95  by means of packages with  ABSTRACT data types. The
  439.     peculiarity  of  these  packages  is  the  absence  of body subprograms
  440.     because the realization does not yet permit body definition during this
  441.     stage. We want to introduce complex numbers but have not yet decided on
  442.     their  presentation (cartesian,  polar or   mix) at  this stage  of the
  443.     system design.
  444.  
  445.         PACKAGE ROOT IS
  446.                 TYPE DATA IS ABSTRACT TAGGED NULL RECORD;
  447.                 FUNCTION "+"(X,Y:DATA) RETURN DATA IS ABSTRACT;
  448.                 FUNCTION "-"(X,Y:DATA) RETURN DATA IS ABSTRACT;
  449.                 FUNCTION "*"(X,Y:DATA) RETURN DATA IS ABSTRACT;
  450.                 FUNCTION "/"(X,Y:DATA) RETURN DATA IS ABSTRACT;
  451.         END ROOT;
  452.  
  453.         This  package has  introduced abstract  type DATA  and declared the
  454.     primitive operations. Now we can  create child package root.complex and
  455.     declare type complex_type.
  456.  
  457.         PACKAGE ROOT.COMPLEX_CARTESIAN IS
  458.                 TYPE COMPLEX_TYPE IS NEW DATA WITH PRIVATE;
  459.                 FUNCTION "+"(X,Y:COMPLEX_TYPE) RETURN COMPLEX_TYPE;
  460.                 FUNCTION "-"(X,Y:COMPLEX_TYPE) RETURN COMPLEX_TYPE;
  461.                 FUNCTION "*"(X,Y:COMPLEX_TYPE) RETURN COMPLEX_TYPE;
  462.                 FUNCTION "/"(X,Y:COMPLEX_TYPE) RETURN COMPLEX_TYPE;
  463.  
  464.         PRIVATE
  465.                 TYPE COMPLEX_TYPE IS NEW DATA WITH RECORD
  466.                 RE :FLOAT;
  467.                 IM :FLOAT;
  468.                 END RECORD;
  469.  
  470.         END ROOT.COMPLEX_CARTESIAN;
  471.  
  472.         We can write the  primitive operations "+","-","*","/" and describe
  473.     the package body therefore.
  474.  
  475.         Let  us finally  remark that  ADA-95 gives  users the  unrestricted
  476.     capability to write complicated and safe programs.
  477.  
  478.         Now  we can  study inter  process communications.  What variants of
  479.     these communications we are interested in?
  480.  
  481.         1. There  are fully independent  processes. They start  at the same
  482.     time and  don't interact. For  example, there are  postmen. They go  to
  483.     work in the morning, collect the  correspondence and go away to deliver
  484.     it.
  485.  
  486.         2. There  are  independent processes  which may  be aborted by time
  487.     limit or special signals, for example, there is a blitz-chess.
  488.  
  489.         3. There are processes which  synchronize their acts in fixed clock
  490.     time. For example,  the employees were invited to  the conference at 11
  491.     o'clock. Everybody does his work before  11, they gather at the meeting
  492.     place  at  11  o'clock,  and   everybody  does  his  work  again  after
  493.     conference.
  494.  
  495.         4. There  are processes which  are time independent,  but they work
  496.     with  common  (shared)  objects  and  depend  on their accessibility or
  497.     inaccessibility. For  example, there is  work with a  data base in  the
  498.     correction mode.
  499.  
  500.         5. There are the processes with time and shared objects dependency.
  501.     For example,  the permission to turn  on the fire extinguish  system if
  502.     the protection system has worked for 5 seconds .
  503.  
  504.         TASKs are the  processes called from the main  process and executed
  505.     in parallel  with it. The task  is an object of  the "process" type. We
  506.     use the term "TASK TYPE" for their declarations.
  507.  
  508.         The  task   has  two  execution   methods.  These  methods   repeat
  509.     consistently:
  510.  
  511.         1. There may be an independent asynchronous part ;
  512.         2. There may be a non-independent part requiring synchronization of
  513.     time or data with others tasks.
  514.  
  515.         If the synchronization part is  needn't (post's example) the second
  516.     part is  absent. If the synchronization  is required, the synchronously
  517.     part is named ENTRY and marked in the group
  518.  
  519.      ACCEPT <entry_name>[(parameter list)] DO
  520.      ..........
  521.      END  [<entry_name>];
  522.  
  523.    internal of the task body.
  524.  
  525.         The language has an asymmetric task mechanism if ones tasks require
  526.     rendezvous  with others  for  data  exchange and  synchronization their
  527.     actions.
  528.  
  529.         Thus,  the requiring-rendezvous  task executes  independently until
  530.     the  entry-calling  point.  The  called  on  rendezvous  task  executes
  531.     independently  until its  ACCEPT_statement. Whatever  tasks has arrived
  532.     first,  must wait  for the  partner and  only after  rendezvous may  it
  533.     continue its independent execution.
  534.  
  535.          If one task  object with Entry point called from many others tasks
  536.      then to ACCEPT_statement will be QUEUE and requiring-rendezvous tasks
  537.      will be served in FIFO mode.
  538.  
  539.         Thus the task type, similarly for the package description, requires
  540.     the specification part to declare entry points rendezvous, and the body
  541.     to contain source code to accomplish the needed action. As a rule, some
  542.     device (disk or  elevator ) is connected with task,  but its control is
  543.     connected with entry.
  544.  
  545.         TASK TYPE READCARD IS
  546.                 ENTRY BUFFER(C:OUT CHARACTER) ;
  547.         END READCARD;
  548.  
  549.         Entry description is similar to  the procedure ones. Let us remark,
  550.     that tasks can be declared  with discriminant (record analog), and from
  551.     task  types  we  can  use  both  the  task  objects and the task arrays
  552.     (family).
  553.  
  554.         For example, READERS:ARRAY(1..8) OF READCARD;
  555.  
  556.       If you want to connect device interruption with Entry point you may
  557.    do it. For example task semaphore:
  558.  
  559.        TASK LIGHT is
  560.          entry STOP ; -- button to stop traffic
  561.          for STOP'address use 16#100# ;  -- address interruption
  562.       end LIGHT ;
  563.  
  564.       In this example describe semaphore controlled task LIGHT with entry
  565.       STOP for stopping traffic. In main program or others tasks needn't
  566.       to write LIGHT.STOP for calling entry because calling modeled
  567.       by means of turning on button on semaphore and takes interruption
  568.       at address 16#100#.
  569.  
  570.         The task starts at once after the object declaration (after BEGIN).
  571.     But how can we control its start and finish ?
  572.  
  573.         The  task  finish  may  be  natural  (  end  of  task body), normal
  574.     (execution TERMINATE_statement) and abnormal (execution ABORT_statement
  575.     from other tasks).
  576.  
  577.         The  task  start  is  a  more  complex  problem.  The  direct start
  578.     mechanism is absent  but the indirect mechanism is  provided via ACCESS
  579.     types. The task type (similarly to any other) can be connected with the
  580.     access type.  The task object  is dynamically created  by the generator
  581.     NEW .
  582.  
  583.         The  task   execution  is  suspended   until  partners  reach   the
  584.     rendezvous-point and waiting may be unlimited in a time.
  585.  
  586.         How can we limit the rendezvous  wait time or refuse the rendezvous
  587.     with the task A and require the rendezvous with the task B ?
  588.  
  589.         The language has a SELECT_statement for this goal.
  590.  
  591.         An example follows.  The students have arrived at  the lecture, but
  592.     the professor  is absent. How  long they must  wait for a  rendezvous ?
  593.     Assume that they have decided to wait 15 seconds. Then we must write
  594.  
  595.         SELECT
  596.         DELAY 15.0;
  597.         GOHOME;
  598.         THEN ABORT
  599.         Student.LECTURE;
  600.         END SELECT;
  601.  
  602.         But  students may  arrive early  at the  lecture. More correctly we
  603.     should write:
  604.  
  605.         SELECT
  606.           DELAY UNTIL Time_encounter+15.0;
  607.           GOHOME;
  608.           THEN ABORT
  609.           Student.LECTURE;
  610.         END SELECT; -- where Time_encounter is the time set for the lecture.
  611.  
  612.         We  can  guarantee  safe  work  with  shared  data  by means of the
  613.     SELECT_mechanism, as in the calling task or in the called task, but the
  614.     ADA-95 has more elegant solution. This is the PROTECTED types.
  615.  
  616.         The protected type  is a little "kingdom" in  which is declared the
  617.     objects, the procedures, the functions and the entrees.
  618.  
  619.         The shared  data, used by  different tasks, must  be protected from
  620.     use during changes.
  621.  
  622.         All data manipulations  can be done only by  means of the protected
  623.     functions for  reading only, the protected  procedures for monopolizing
  624.     changing  and the  protected entry  for the  synchronizing. The boolean
  625.     object-semaphore allows  or prohibits shared data  reformation in entry
  626.     calls. It keeps waiting for the its TRUE value.
  627.  
  628.         Consider a simple and frequent example, the system timer.
  629.  
  630.         WITH ADA.CALENDAR;
  631. ---------------------
  632.         TYPE SYSTEM_TIME IS NEW ADA.CALENDAR.TIME;
  633.  
  634.         PROTECTED TYPE SYSTEM_CLOCK IS
  635.                 FUNCTION READ_TIME(TM:SYSTEM_TIME) RETURN STRING;
  636.                 ENTRY CAN_CHANGE(NT:STRING;TM:IN OUT SYSTEM_TIME);
  637.                 PRIVATE
  638.                 ENTRY FREE_TIME;
  639.                 FLAG:BOOLEAN:=FALSE;
  640.                 END SYSTEM_CLOCK;
  641.  
  642.         PROTECTED BODY SYSTEM_CLOCK IS
  643.  
  644.                 FUNCTION READ_TIME(TM:SYSTEM_TIME) RETURN STRING IS
  645.                 BEGIN
  646.                         @@..........................
  647.                 END READ_TIME;
  648.  
  649.         ENTRY CAN_CHANGE(NT:STRING;TM:IN OUT SYSTEM_TIME) WHEN NOT FLAG IS
  650.                 BEGIN  FLAG:=TRUE;
  651.                 TM:=.... ;-- implementation define;
  652.                 REQUEUE  FREE; --
  653.         END CAN_CHANGE;
  654.  
  655.         ENTRY FREE WHEN TRUE IS
  656.                 BEGIN FLAG:=FALSE;
  657.         END FREE;
  658.         END SYSTEM_CLOCK;
  659.  
  660.         ST_CLOCK:SYSTEM_CLOCK; -- protected object
  661.         TM:SYSTEM_TIME;
  662.  
  663.         We can read time from any tasks in any moment.
  664.  
  665.         TMM:=CLOCK.READ_TIME(TM);
  666.  
  667.         But the actual system time change  can be accomplished by the entry
  668.     CAN_CHANGE  and  only  by  the  condition  FLAG=FALSE.  It's  the  main
  669.     condition of execution.
  670.  
  671.         The statement REQUEUE for private entry FREE has done TMM access to
  672.     change from others  tasks. The requeue statement is  designed to handle
  673.     two main situations:
  674.  
  675.         - after an accept statement or  entry body begins execution, it may
  676.     be  determined  that  the  request  cannot  be  satisfied  immediately.
  677.     Instead, there is a need to requeue the caller until the request can be
  678.     handled.
  679.  
  680.         - alternatively,  part of the  request may be  handled immediately,
  681.     but  there may  be additional  steps  in  the process  that need  to be
  682.     performed at a later point.
  683.  
  684.   I would be like to do two examples used REQUEUE statement.
  685.  
  686. First : You go to hospital first and you need dentist but present only
  687.         surgeon  and pediatrician.
  688.    1.   You may wait dentist and nobody in queue can go to doctors
  689.         (perhaps they need surgeon or pediatrician).
  690.         There is calling entry with barrier.
  691.    2.   You may go to tail of queue and others may go to doctors.
  692.         There is REQUEUE statement.
  693.  
  694.     Second: You are invited to boss but he is busy.
  695.     1.   You may wait boss free ( entry with barrier)
  696.     2.   You may come back to work ( REQUEUE statement with ABORT).
  697.  
  698.     Or next example :
  699.     Protected type behaves as the king, nominating audience, and a tasks
  700.     causing ENTRY point as the ambassadors, desiring to receive it.
  701.     Because in audience time the king communicates only with one
  702.     ambassador,there is the queue. And there where the present queue  there is
  703.     some priorities system. In elementary case when everyone are equal -
  704.     it is FIFO (who earlier has come, that earlier have served) In more complex
  705.     case in queue there is the moving according to priority.
  706.     Some very proud ambassadors can not wish to stand in queue (REQUEUE
  707.     with ABORT), and some "very petty " can simply deliver in tail (REQUEUE).
  708.  
  709.         The  task  types  and  protected  types  may  be  declared  only in
  710.     subprograms or packages. They are the  PRIVATE LIMITED types and can be
  711.     used as parameters in the subprograms directly or by access.
  712.  
  713.         It  is impossible  to give  a full  description of  Ada-95 in  this
  714.     little  paper,  but  I  hope  that  now  you  can read ISO standard and
  715.     understand it.
  716.  
  717.