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,e55245590c829bef X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!j25g2000yqa.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Beginners question: Compound types, how-to? Date: Wed, 3 Nov 2010 22:18:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: <63005b18-6a23-4980-ae4b-f0f84d3eb63e@j25g2000yqa.googlegroups.com> References: <86wroy58ff.fsf@gareth.avalon.lan> <86pqup5xfy.fsf@gareth.avalon.lan> <86y69d3rec.fsf@gareth.avalon.lan> <4cd19583$0$6977$9b4e6d93@newsspool4.arcor-online.net> <4cd1e5b0$0$6974$9b4e6d93@newsspool4.arcor-online.net> NNTP-Posting-Host: 174.28.219.200 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1288847922 10170 127.0.0.1 (4 Nov 2010 05:18:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 4 Nov 2010 05:18:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j25g2000yqa.googlegroups.com; posting-host=174.28.219.200; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729; .NET4.0E),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:16167 Date: 2010-11-03T22:18:42-07:00 List-Id: Somewhere on this thread, a while back, someone brought up the question about why the Standard numeric types (Integer, Float, etc) don't have a "_Type" suffix as an argument against such a suffix. After some thought it dawned on me that because the name like integer & natural are the names of the [mathematical, nor programming] type of numbers they are. That is to say that the _Type is implicit in the name itself. We have this abstract class of type "number," which is precisely what some quantity is... derived from this are the abstract types "Real" and "Integer" [this "Integer" is Universal_Integer of the ARM]. I'll stick with the Universal_Integer right now for simplicity's sake, but there are further abstract types/sets within "Integer," things like "Natural" {the counting numbers 1...}, "Whole" (0 U counting numbers), and "Negative" (0 less some x where x is a counting number). In the design of Ada they chose to map "whole" numbers to the name Natural, and from there they defined the name Positive to map to the counting numbers. This allows us to use sets to work with all the integers representable on a computer (negative being "Range Integer'First to Intger'Pred(Natural'First)" or perhaps "ix X Not In Natural'Range then" ). Real numbers are a bit more tricky. Because we're using a digital machine we cannot represent real numbers [as such] but have to make do with intervals {the 'accuracy' of the computer} in addition to the finite representation range imposed on integers. {This is actually the same problem as integers, but once-recursive: there is no way to represent the infinite set of integers, but reals have the added infinite range between two integers.} It is a bit of tradition in CS that the floating-point method of representing reals be called "float," probably precisely to remind programmers that they were NOT dealing with the exactly mathematically- representable type "Real" but an approximation thereof. Ada also offers the "fixed point" method of representing real numbers, which requires far less consideration about the implementational-differences/ shortcomings of "float" [of the 'Specification" of mathematical Real numbers]. Take something like money; here in the US we use the Dollar and subdivide it into 100 cents and no further [not entirely true, once we had half-pennies]. So to represent the concept "money" we can have a fixed-point type with the increment/accuracy set to 1/100th. (Conceptually there isn't much difference from that method and simply counting money-quantities in cents grouping out "dollars" and "cents" with the mod and '/' operations.) There is a third way of representing reals [or rather a subset} which would be the rational method: Type Rational is record Numerator, Denominator : Integer; end record; But this method, the user-defined one is different from the others in that the designers of Ada did not provide it as a part of Standard.