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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,ef0074ec236ba6e3 X-Google-Attributes: gid109fba,public X-Google-Thread: 108717,ef0074ec236ba6e3 X-Google-Attributes: gid108717,public X-Google-Thread: 1108a1,ef0074ec236ba6e3 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,b19fa62fdce575f9 X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,ef0074ec236ba6e3 X-Google-Attributes: gid1014db,public X-Google-ArrivalTime: 1994-12-06 14:46:53 PST Newsgroups: comp.lang.ada,comp.lang.c,comp.programming,comp.lang.c++,comp.object Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swrinde!pipex!uunet!zib-berlin.de!informatik.tu-muenchen.de!lrz-muenchen.de!news.informatik.uni-muenchen.de!news.muc.de!isis.muc.de!mike From: Mike.Chapman@muc.de (Mike Chapman) Subject: Physical Types (was Why don't large companies use Ada?) Followup-To: comp.lang.ada,comp.lang.c,comp.programming,comp.lang.c++,comp.object X-Newsreader: TIN [version 1.2 PL2] Organization: Home Message-ID: <1994Dec6.201030.366@isis.muc.de> References: <3aa7jo$7j@Starbase.NeoSoft.COM> <3bjf2q$i69@goanna.cs.rmit.oz.au> <3bvadv$66p@holly.csv.warwick.ac.uk> Date: Tue, 6 Dec 1994 20:10:30 GMT Xref: bga.com comp.lang.ada:8357 comp.lang.c:33615 comp.programming:5664 comp.lang.c++:39886 comp.object:9527 Date: 1994-12-06T20:10:30+00:00 List-Id: Jules (csusb@csv.warwick.ac.uk) wrote: : In article , : bobduff@dsd.camb.inmet.com (Bob Duff) writes: : >In article <3bjf2q$i69@goanna.cs.rmit.oz.au>, : >Michael Coburn wrote: : >>house@helios.usq.EDU.AU (ron house) writes: : >> : >>>How about "Ada - use it when you want to multiply a length by a length : >>>and get a length, or when you want to be prevented from dividing an area : >>>by a length because they have different types." : >> : >>total_area := area(length_one) * area(length_two); : >> : >>yawn.... : > : >The fact remains that Ada's type model disallows a sensible operation : >(Total_Area := Length_One * Length_Two), and allows nonsense : >(Some_Length := Length_One * Length_Two). : Only if you want to go completely over the top and define new types for lengths : and areas. I mean, if you did the same in C++ you would get the same results. : So why criticise Ada, for something which almost all commonly used languages : today have a problem with, if you use them in this (unusual) manner? There is a language called VHDL which was developed for modelling integrated circuits. It is based on Ada. You can actually write code which would compile and run with Ada as well as compile and simulate (you don't run VHDL code!) in VHDL. In this language you can define 'physical units' For instance, type distance is range -1E18 to 1E18 units -- Base unit A; -- angstrom nm = 10 A; -- nanometer um = 1000 nm; -- micron mm = 1000 um; -- millimeter cm = 10 mm; -- centimeter m = 1000 mm; -- meter km = 1000 m; -- kilometer end units; variable x: distance; variable z: integer; x := 5 A + 13 m - 25 um; x := 4 * x; z := x / mm; However x * x is undefined. You can of course overload it if you have defined a physical type area in the obvious way.... function "*" (l,r: in distance) return area is begin return (l/A)*(r/A)*A2; end "*"; where A2 are square angstroms defined in a physical area type. Similiarly function "/" (l: in area; r: in distance) return distance is begin return ((l/A2)/(r/A))*A; end "/"; I am surprised something like this has not been added into the Ada 9x proposals. -- Mike Chapman As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality. -- Albert Einstein --