home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / os2 / misc / 37020 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  8.6 KB

  1. Path: sparky!uunet!spool.mu.edu!uwm.edu!rpi!batcomputer!munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!levels!magrw
  2. From: GEORGE.WILEY@levels.unisa.edu.au
  3. Newsgroups: comp.os.os2.misc
  4. Subject: Re: The Confusions of ALL OS/2 UPDATES
  5. Followup-To: comp.os.os2.misc
  6. Date: 19 Nov 92 11:46:31 +1030
  7. Organization: University of South Australia
  8. Lines: 220
  9. Message-ID: <19348.2b0b7e97@levels.unisa.edu.au>
  10. References: <BxIxvE.MEI@ccu.umanitoba.ca> <473@bertha.HyperDesk.com>
  11. NNTP-Posting-Host: sirius.itd.adelaide.edu.au
  12. Originator: daemon@sirius.ucs.adelaide.edu.au
  13.  
  14. >The CSD fixes some problems that had no work-around.  It does introduce
  15. >a couple of other bugs wich are cosmetic in nature.  For example, you
  16. >might lose the ability to use alt-home to switch between full and
  17. >windowed dos sessions.  You can still use other methods to make the
  18. >switch.
  19.  
  20. It was only after reading this that I realised that I had this problem!
  21.  
  22. However, I don't know of any other methods of making this switch.
  23.  
  24.  
  25. Perhaps, someone would care to enlighten me.
  26.  
  27.  
  28. Thanks.
  29.  
  30. George Wiley,
  31. University of South Australia,
  32. Adelaide, Australia.
  33. #! rnews 7683
  34. Path: levels!maajs
  35. From: maajs@levels.unisa.edu.au
  36. Newsgroups: unisa.cis.ada
  37. Subject: Tutorial solutions for week 9 (10?)
  38. Message-ID: <19349.2b0b8e91@levels.unisa.edu.au>
  39. Date: 19 Nov 92 12:54:40 +1030
  40. Organization: University of South Australia
  41. Lines: 191
  42.  
  43. Programming in Ada,   Tutorial solutions for week 9.
  44.  
  45.  
  46. 1.
  47. Ada declaration for type colours:
  48.  
  49.         type colours is (red, green, blue, cyan, magenta, yellow, black, white);
  50.  
  51. A subtype is a declared by placing a (optional) constraint on an existing type
  52. (the parent type).  Variables of the subtype are compatible with the parent
  53. type.  The subtype simply places a constraint on the range of values of valid
  54. values for a variable of the subtype.  For example:
  55.  
  56.         subtype primary_colours is colours range red .. blue;
  57.  
  58. declares a subtype primary_colours where the only valid values are  red, green
  59. and blue.  With variable declarations
  60.  
  61.         c1 : colours := red;
  62.         c2 : primary_colours := green;
  63.  
  64. we could make the assignment
  65.  
  66.         c2 := c1;
  67.  
  68. and
  69.         c1 := c2;
  70.  
  71. however the assignment
  72.  
  73.         c2 := cyan;
  74.  
  75. would cause a constraint_error to be raised as cyan is outside the valid range
  76. of values for c2.
  77.  
  78. A derived type is declared by placing an (optional) constraint on an existing
  79. type, but declaring it as a new type.  For example:
  80.  
  81.         type tints is new colours range red .. yellow;
  82.  
  83. This declaration creates a new type tints derived from colours but which is
  84. incompatible with the type colours.   This declaration also creates overloadings
  85. for the enumeration values red to yellow. If we declare variables
  86.  
  87.         c1 : colours := red;
  88.         c2 : tints := green;
  89.  
  90. then attempts to assign c1 to c2 or vice versa will result in compilation errors
  91. as the two types are incompatible and cannot be mixed.
  92.  
  93. In summary,  derived types create a new type which is not compatible with the
  94. parent type while subtypes do not create a new type, but simply place an additional
  95. constraint on values of the parent type.
  96.  
  97.  
  98. 2.
  99. Discuss the meaning and usage of the with and use declarations in an Ada program.
  100.  
  101. Ada programs normally consist of a number of program units, with one of the
  102. program units being the `main program'.  The dependencies between the program
  103. units is specified by use of with declarations.  If a program unit needs to
  104. use resources (such as types, procedures, functions, constants, or variables)
  105. from another program unit, it must `with' the unit.  For example, suppose a
  106. stand alone procedure test needs to use procedures from package text_io,
  107. then the procedure declaration must be preceed by a with declaration:
  108.  
  109.         with text_io;
  110.         procedure test is
  111.           ...
  112.  
  113. Now the objects declared in text_io can be used within the procedure test using
  114. a dot notation, such as:
  115.  
  116.         text_io.new_line;
  117.  
  118. A program unit can `with' any number of other program units.
  119.  
  120. The `with' declaration does not make the objects in a program unit directly
  121. visible,  and this can make usage, particularly of types, cumbersome.  For
  122. example,  if a package example contains a declaration of a derived type:
  123.  
  124.         type count is new positive range 1 .. 1000;
  125.  
  126. and a procedure test with's the package example and declares a variable val
  127. of type example.count.  Now a simple test such as
  128.  
  129.         if (val = 1) then
  130.             ...
  131.  
  132. would have to be expressed as
  133.  
  134.         if example."="(val,1)
  135.  
  136. as the operator example."=" is not directly visible.  One way of making the
  137. operator (and all other objects in the package example) directly visible is
  138. via the declaration 'use example;'.  This can only be used if the package is
  139. visible (which usually done via a `with' declaration), and often follows just
  140. after a with declaration.  For example:
  141.  
  142.         with example;
  143.         use example;
  144.         procedure test is
  145.           ...
  146. However, excessive use of the the `use' declaration can cause the number of
  147. directly visible objects to be very high,   reducing the readability and maintainability
  148. of the code.   In addition,  it may cause unexpected overloadings of objects,
  149. which can lead to incorrect code.  In general,  the number of packages in the
  150. `use' declarations should be kept to a minimum,  with one or two being reasonable.
  151.  
  152. 3.
  153. Private and limited privage types in Ada have restrictions on where they are
  154. declared,   and impose restrictions on the usage of variables of these types.
  155.   Unlike non-private types,  private and limited private types can only be
  156. declared in package specifications.   These types are declared as private or
  157. limited private,   and the declarations are completed in the private part of
  158. a package declaration.  For example:
  159.  
  160.         package demo is
  161.             type a is private;
  162.             type b is limited private;
  163.             ...
  164.         private
  165.             type a is range 1..10;
  166.             type b is record
  167.                     real, imaginary : float;
  168.                             end record;
  169.         end demo;
  170.  
  171. Private types are intended to be used to declare abstract data types where
  172. the valid operations on values of the type are specified in the package where
  173. the type is declared.   The Ada language then imposes restrictions on the usage
  174. of the objects so that the abstraction being implemented by the type is not
  175. violated.  The main restrictions imposed are that:
  176.  
  177. a)
  178. The details of the data structure implemented by objects of a private or limited
  179. private type are not accessible to code outside of the package in which the
  180. type is declared and implemented.
  181.  
  182. b)
  183. Operations on private types are restricted to assignment and test for equality.
  184.  
  185. c)
  186. Neither of these operations are available for limited private types.
  187.  
  188. The lack of the assingment operation for limited private types allows a data
  189. structure which is implemented using an array to be changed to use pointers
  190. without changing the semantics of the assignment operator (as the operator
  191. is not available).  If the assignment operator was available the assignment
  192. of one variable to another would change from making a copy of the variable
  193. to making an alias for a pointer variable.
  194. The requirement for a private type to be completed in the private part of a
  195. package can result in the need to recompile both the specification and the
  196. implentation packages if the data structure is changed.  This can be avoided
  197. by making the type a pointer to a type which is completed in the package body.
  198.  
  199. 4.
  200. Type declarations:
  201.  
  202.         type tree_node;
  203.         type tree is access tree_node;
  204.         type tree_node is record
  205.                         data : integer;
  206.                         count : natural;
  207.                         left, right : tree;
  208.                           end record;
  209.  
  210. Note that the record type tree_node must be declared before a pointer to it,
  211.  so an incomplete type declaration is required.
  212. The code for the procedure add is:
  213.  
  214.         procedure add(the_data      : in        integer;
  215.                      to_the_tree : in out tree) is
  216.         begin
  217.             if the_data = to_the_tree.data then
  218.                 to_the_tree.count := to_the_tree.count + 1;
  219.             elsif the_data < to_the_tree.data then
  220.                 add(the_data, to_the_tree.left);
  221.             else
  222.                 add(the_data, to_the_tree.right);
  223.             end if;
  224.         exception
  225.             when constraint_error =>
  226.                 to_the_tree := new tree_node'(the_data, 1, null, null);
  227.         end add;
  228.  
  229. Note that when to_the_tree is null,  an attemp to access a component of the
  230. record `pointed' to by to_the_tree will result in a constraint_error exception
  231. being raised.  This exception is handled by creating a tree_node with the appropriate
  232. values in it and assigning a pointer to it to to_the_tree.
  233.  
  234.