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!news2.google.com!news.glorb.com!news2.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-07.dc1.easynews.com.POSTED!not-for-mail From: Rob Solomon Newsgroups: comp.lang.ada Subject: Re: unsigned type Message-ID: <82oq45tj2uu26u6ecsgq70bsjskr9dvghr@4ax.com> References: <59O1m.404661$4m1.69194@bgtnsc05-news.ops.worldnet.att.net> <62792744-daca-437b-bdee-4b8a21f7ce27@j32g2000yqh.googlegroups.com> X-Newsreader: Forte Agent 4.2/32.1118 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@easynews.com Organization: Forte Inc. http://www.forteinc.com/apn/ X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Thu, 02 Jul 2009 21:41:37 -0400 Xref: g2news2.google.com comp.lang.ada:6814 Date: 2009-07-02T21:41:37-04:00 List-Id: >Rob Solomon wrote on comp.lang.ada: >> I was able to use the Natural and Positive. � >> >> 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 := Long_Integer(c32); >> >> How to I output c31 and c32? �Modula-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.Text_IO.Put_Line (Card31'Image (c31)); > >or > > package C31_IO is new Ada.Text_IO.Modular_Text_IO (Num => Card31); >begin > C31_IO.Put (c31); > >But I have three suggestions: > >- rather than "type card31 is mod 2_147_483_648", write "type card31 >is mod 2**31;" > >- do not declare machine-oriented types like card31 or card32 in the >first place; instead, define application-oriented types like >"Temperature" or whatever > >- before you define modular types, explain to yourself why you need >the wrap-around semantics or the bitwise operators (modular types have >them, signed integer types don't). I am trying to learn the language, so that is why I'm playing w/ these. I am very familiar w/ Modula-2 and am trying to extend what I do know to what I don't. I bought Programming In Ada 2005 by John Barnes and Ada as a Second Language by Norman Cohen. Ada as a Second Language is a far better book to learn from. My earlier posts were because I first opened the John Barnes book and that left me w/ more questions than answers. It introduces very advanced concepts like OOP, pointers, abstract types, etc before loops are covered. That is, he writes about advanced data structures before covering more basic control structures. This made it very hard for me to follow. So I am going onto the Norman Cohen book. This is much better organized for a newcomer. I learned how to program by punching cards; I know how to write programs. Norm Cohen is much better at instruction than John Barnes. I will keep reading before I post much more. --rob