home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / modula3 / 1148 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1.4 KB  |  69 lines

  1. Newsgroups: comp.lang.modula3
  2. Path: sparky!uunet!newsgate.watson.ibm.com!yktnews2.watson.ibm.com!yktnews!admin!rhoover
  3. From: rhoover@watson.ibm.com (Roger Hoover)
  4. Subject: generics that use generics
  5. Sender: news@watson.ibm.com (NNTP News Poster)
  6. Message-ID: <1993Jan25.142856.18843@watson.ibm.com>
  7. Date: Mon, 25 Jan 1993 14:28:56 GMT
  8. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  9. Nntp-Posting-Host: trek.watson.ibm.com
  10. Organization: IBM T.J. Watson Research Center
  11. Lines: 56
  12.  
  13.  
  14. I'd like to write a generic that extends another generic.  For
  15. example, consider the generic List:
  16.  
  17. --
  18. GENERIC INTERFACE List(El);
  19.  
  20. TYPE T <: REFANY;
  21.  
  22. PROCEDURE RemoveFirst(VAR l: T): El.T;
  23. PROCEDURE InsertFirst(VAR l: T, x: El.T);
  24.  
  25. END List.
  26.  
  27. --
  28. GENERIC MODULE List(El);
  29.  
  30. REVEAL
  31.   T = BRANDED OBJECT
  32.     el: El.T;
  33.     next: T := NIL;
  34.   END;
  35.  
  36. PROCEDURE RemoveFirst(VAR l: T): El.T =
  37. VAR r: El.T;
  38. BEGIN
  39.   <*ASSERT l # NIL*>
  40.   r := l.el
  41.   l := l.next;
  42.   RETURN r
  43. END RemoveFirst;
  44.  
  45. PROCEDURE InsertFirst(VAR l: T, x: El.T) =
  46. BEGIN
  47.   l := NEW(T, el := x, next := l)
  48. END InsertFirst;
  49.  
  50. END List.
  51.  
  52. --
  53. I'd like to create a generic Stack that uses List:
  54. GENERIC INTERFACE Stack(El);
  55.  
  56. TYPE T <: REFANY;
  57.  
  58. PROCEDURE Pop(VAR l: T): El.T;
  59. PROCEDURE Push(VAR l: T, x: El.T);
  60.  
  61. END Stack.
  62.  
  63. Is there any way to write GENERIC MODULE Stack(El) using the
  64. List.RemoveFirst procedure for Pop and ListInsertFirst for
  65. Push?
  66.  
  67. roger
  68. rhoover@watson.ibm.com
  69.