home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / ada / 3311 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  1.7 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!biosci!agate!dog.ee.lbl.gov!news!nosc!dale.cts.com!jhb
  2. From: jhb@dale.cts.com (John Bollenbacher)
  3. Newsgroups: comp.lang.ada
  4. Subject: re: [null arrays]
  5. Message-ID: <Bxz5M0.AxC@dale.cts.com>
  6. Date: 19 Nov 92 17:51:32 GMT
  7. Sender: news@dale.cts.com (USENET News Account)
  8. Organization: Titan Linkabit Corporation
  9. Lines: 41
  10. X-Newsreader: Tin 1.1 PL5
  11.  
  12. Thanks to all that responded to my initial mail on this thread.  I have a
  13. followup question.  Is there a more straightforward way to code the function 
  14. (REMOVE) below, given the restriction on sliding in aggregate creation?
  15.  
  16. package TEST is
  17.   subtype T is NATURAL range 0 .. 10;
  18.  
  19.   type ARR is array (T range <>) of BOOLEAN;
  20.   
  21.   type A(N : T := 0) is record 
  22.     DATA : ARR(1..N);
  23.   end record;  
  24.  
  25.   function REMOVE(ELEMENT : BOOLEAN;
  26.                   FROM    : A) return A;
  27.   
  28. end TEST; 
  29. package body TEST is
  30.   function REMOVE(ELEMENT : BOOLEAN;
  31.                   FROM    : A) return A is
  32.     RESULT : ARR(1..FROM.N-1);
  33.   begin
  34.     for I in FROM.DATA'RANGE loop
  35.       if FROM.DATA(I) = ELEMENT then
  36.         RESULT := FROM.DATA(1..I-1) & FROM.DATA(I+1..FROM.N);
  37.         return (FROM.N - 1, RESULT);
  38.       end if;
  39.     end loop;    
  40.     return FROM;
  41.   end REMOVE; 
  42.   
  43. end TEST;
  44.  
  45.  
  46. --
  47. -----------------------------------------------------------------------------
  48. - John Bollenbacher                                        jhb@dale.cts.com -
  49. - Titan Linkabit Corp.                                       (619) 552-9963 -
  50. - 3033 Sience Park Rd.                                                      -
  51. - San Diego, Ca. 92121                                                      -
  52. -----------------------------------------------------------------------------
  53.