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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fe5e779eaf4ecf02 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!r66g2000hsg.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Returning ranges from a function (was: How to loop (elegant) throug a vector ?) Date: Sun, 22 Jun 2008 07:01:11 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6ebe0cd8-288e-4997-94d7-61905fd2dfc0@r66g2000hsg.googlegroups.com> References: <20080620191237.5971480b@cube.tz.axivion.com> NNTP-Posting-Host: 85.3.83.61 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1214143272 26202 127.0.0.1 (22 Jun 2008 14:01:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 22 Jun 2008 14:01:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r66g2000hsg.googlegroups.com; posting-host=85.3.83.61; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:800 Date: 2008-06-22T07:01:11-07:00 List-Id: On 20 Cze, 19:12, Stefan Bellon wrote: > Now you can do the following: > > function Get_Range > return Integer_Range_Objects.Range_Type > is > begin > return (42 .. 128 => <>); > end Get_Range; > > And then: > > for I in Get_Range'Range loop > Do_Something (I); > end loop; > > It's not as elegant as I wished (because of the additional 'Range), but > it is simple and light-weight enough to be usable. As far as I can tell, it creates the physical array that might not be necessarily optimized out by the compiler. You need to store it somewhere. It would be nicer to return a "range" that is not dependent on memory constraints. See xrange in Python. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com