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: a07f3367d7,caabf5265fad78e5 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!l2g2000vba.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: unsigned type Date: Mon, 29 Jun 2009 08:37:31 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9d1f9a63-1992-4a34-a9a9-a76310d8ee1c@l2g2000vba.googlegroups.com> References: <59O1m.404661$4m1.69194@bgtnsc05-news.ops.worldnet.att.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1246289852 24670 127.0.0.1 (29 Jun 2009 15:37:32 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 29 Jun 2009 15:37:32 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l2g2000vba.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6720 Date: 2009-06-29T08:37:31-07:00 List-Id: On Jun 29, 6:36=A0am, Rob Solomon wrote: > I was able to use the Natural and Positive. =A0 > > Now I'm trying to understand Mod types. > > I tried this: > type card31 is mod 2_147_483_648; > type card32 is mod 4_294_967_296; > c31 : Card31; > c32: Card32; > LI : Long_Integer; > and > > LI :=3D Long_Integer(c32); > > How to I output c31 and c32? =A0Modula-2 uses WriteCard or CardToString > and WriteString > > I tried using Put, but I got an error saying that correct procedure > could not be found, or something like that. > > Put(LI) works until the value of LI > 2**31, even for c32. Ada is a strongly typed language. "Integer" is a type (defined by the language); but whenever you declare a new type with a "type" statement (whether it's a modular type, another signed integer type, or something else), it will be a new type, and you can't automatically use values of this new type in places where a value of type Integer is expected. The advantage of this is that you can define types for separate purposes, so that if you declare a real type "Distance" and another real type "Velocity", for example, you can't accidentally use a Distance value as a parameter to a procedure that wants a Velocity, e.g. The "Put" routine you're using is probably from the Ada.Integer_Text_IO package; that routine needs an Integer parameter and won't accept a value of any other type, even another integer type. You can create a Put routine that accepts a value of the type you want by generic instantiation. For a modular type, an instance of Ada.Text_IO.Modular_IO (see Georg's post) will create a new package that has a Put routine with the right parameter type. The strong typing aspect of Ada is something that trips up a lot of new Ada programmers, so it's something that I think you do need to understand. I don't know Modula-2 so I don't know whether this concept is already familiar to you. -- Adam