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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.58.253.33 with SMTP id zx1mr11540679vec.10.1390872789501; Mon, 27 Jan 2014 17:33:09 -0800 (PST) X-Received: by 10.50.79.228 with SMTP id m4mr9446igx.9.1390872789270; Mon, 27 Jan 2014 17:33:09 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!k15no8062385qaq.0!news-out.google.com!wo6ni16igb.0!nntp.google.com!uq10no4608705igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 27 Jan 2014 17:33:08 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9c721578-f490-47bb-86a5-b5330828df06@googlegroups.com> Subject: Re: need help learning Ada for a modula-2 programmer From: adambeneschan@gmail.com Injection-Date: Tue, 28 Jan 2014 01:33:09 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3147 X-Received-Body-CRC: 1707961212 Xref: news.eternal-september.org comp.lang.ada:18304 Date: 2014-01-27T17:33:08-08:00 List-Id: On Monday, January 27, 2014 5:06:43 PM UTC-8, ag...@drrob1.com wrote: > The following code does not compile. I don't understand why. >=20 > The string processing fails to compile, saying "prefix of image must > be a type" >=20 > and=20 >=20 > "move is undefined" The syntax of 'Image in Ada is Type'Image(Value), not Value'Image. Since M= 0 is a Natural, instead of M0'Image you would say Natural'Image(M0). (Some= compilers accept M0'Img, but that is not part of the Ada standard. Compil= ers are allowed to define their own attributes such as 'Img.) There's no built-in Move procedure. Also, you need to be aware that the "S= tring" type is a fixed-length array of characters; it isn't suitable for va= riable-length strings unless you keep track of the length yourself. If thi= s is what you want, you should use the type Unbounded_String in the package= Ada.Strings.Unbounded. The way you've written it: PROCEDURE MDY2STR(M,D,Y : Natural; MDYSTR : Out String255) is=20 IntermedStr : String(1..10);=20 Move(IntermedStr,MDYSTR); The way you'd copy a string, or part of it, is just to assign it with :=3D.= However, this won't work: MDYSTR :=3D IntermedStr; because the two Strings are different lengths. To assign the first 10 char= acters of MDYSTR, you need to do something like MDYSTR(MDYSTR'First .. MDYSTR'First + IntermedStr'Length - 1) :=3D Interm= edStr; where MDYSTR'First is the first index (which is always 1, because of how yo= u defined String255, but it's still best not to hardwire values when you ca= n avoid it); IntermedStr'Length is always 10, so this will assign to charac= ters 1..10 of MDYSTR. However, the remaining characters of MDYSTR will be = unchanged and may be garbage. Working with strings of differing lengths li= ke this can get difficult, which is why you may want to look into Unbounded= _String which will take care of a lot of that for you. -- Adam