From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,223570f8a5a85f0a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!wn14feed!worldnet.att.net!attbi_s02.POSTED!53ab2750!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: unbound array? References: <41046a70@dnews.tpgi.com.au> X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 24.6.132.82 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s02 1090820587 24.6.132.82 (Mon, 26 Jul 2004 05:43:07 GMT) NNTP-Posting-Date: Mon, 26 Jul 2004 05:43:07 GMT Organization: Comcast Online Date: Mon, 26 Jul 2004 05:43:07 GMT Xref: g2news1.google.com comp.lang.ada:2388 Date: 2004-07-26T05:43:07+00:00 List-Id: >The problem I am facing is that I don't know how many words I will encounter >in the text file. I do not want to constrain size to 100 as I have above. I > But it would be a little ridiculous assigning "size" = "number of > characters in text file". If "words" must be separated by blanks or other punctuation, then size := size of text file/2 will always do. If it's real text, with a known statistical word length distribution, you can use size = a large but reasonable size + file_size/(avg_word_and_punctuation_size) and, by choosing the first parameter you can make it arbitrarily improbable that the data will overflow your array. A q&d approach for small files could use recursion: type word_lengths is range 1 .. whatever is reasonable type length_type is array (integer range <>) of word_lengths; function add_a_count(current_list : length_type) return length_type is begin if end of file then return current_list; else return add_a_count(current_list & (read_next_length)); end if; end add_a_count; null_length : length_type(1 .. 0); word_length : length_type := add_a_count(null_length); Perhaps more practical would be to do it in chunks of some suitable size, recursing only if the current chunk became full.