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,782d6c8a12248b09,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!postnews.google.com!t42g2000hsg.googlegroups.com!not-for-mail From: Joe Newsgroups: comp.lang.ada Subject: Ada Recursion with strings Date: Tue, 30 Sep 2008 13:30:14 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 134.240.241.2 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1222806615 18856 127.0.0.1 (30 Sep 2008 20:30:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 30 Sep 2008 20:30:15 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t42g2000hsg.googlegroups.com; posting-host=134.240.241.2; posting-account=ZyfIlgoAAADvwmSv7gUPoyt-iOc2yu_g User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092515 Ubuntu/8.10 (intrepid) Firefox/3.0.3,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2173 Date: 2008-09-30T13:30:14-07:00 List-Id: Hey all, I'm trying to write a function that converts a 2**32 mod type into an string formatted like an IP address (i.e. 192.168.2.1). Here's what I wrote with Ada.Text_IO; use Ada.Text_IO; procedure Ip_packet is type Word_Type is mod 2**32; function IP_String (Word : Word_Type; IP_String : String := "") return String is Sub_String : String := Word_Type'Image(Word mod 2**8); begin if Word <= 2**8 then return Word_Type'Image(Word) & IP_String; else return IP_String( Word / 2**8, "." & Sub_String & IP_String); end if; end IP_String; begin -- Ip_packet Put(IP_String(123456)); end Ip_packet; There are 2 errors with this that I don't understand. First, Ada expects an integer for (word / 2**8). Is this because word_type is outside the standard integer range? How do I get a division operator that works on word_type? If I patch the integer error by type casting word to an integer I get another error. On the second return statement, Ada complains that there are "too many subscripts in array reference". Is there a limitation on the string I can pass to a recursive function call? Thanks, Joe