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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c7f5c70275787af8 X-Google-Attributes: gid103376,public From: "Robert I. Eachus" Subject: Re: Ada vs Delphi? Date: 1999/08/17 Message-ID: <37B9E9F2.D97B79B7@mitre.org>#1/1 X-Deja-AN: 513983153 Content-Transfer-Encoding: 7bit References: <37ab421a.5414989@news.total.net> <37ab8bd1.0@news.pacifier.com> <37ae1fc8.653954@news.clara.net> <7olfni$jsu$1@nnrp1.deja.com> <37b129ae.43419124@news.total.net> <7os8t1$fbd$1@nnrp1.deja.com> <37b54730.55126310@news.total.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.mitre.org X-Trace: top.mitre.org 934930702 15855 129.83.41.77 (17 Aug 1999 22:58:22 GMT) Organization: The MITRE Corporation Mime-Version: 1.0 NNTP-Posting-Date: 17 Aug 1999 22:58:22 GMT Newsgroups: comp.lang.ada Date: 1999-08-17T22:58:22+00:00 List-Id: Andre Ratel wrote: > But how do you avoid complex expressions becoming cumbersome? By defining the operators you need so that the code makes sense. For example: function Clock return Tick; type Tick is new Integer; -- lets assume a 1 millisecond clock. type Seconds is delta 0.001 digits 6; -- let's use a decimal type for kicks. type Minutes is range -186400..186399; ... function "+" (L: Tick; R: Seconds) return Seconds; function "+" (L: Tick; R: Seconds) return Tick; pragma Inline("+"); -- applies to both functions. ... function "+" (L: Tick; R: Seconds) return Seconds is begin return Seconds(L)/1000 + R; end "+"; function "+" (L: Tick; R: Seconds) return Tick is begin return L + Tick(R * 1000); end "+"; Now you can write: Total_Waiting_Time: Seconds := 0.0; ... function Something; Now: Tick := Clock; begin -- waiting ;-) Acquire_Lock; Actually_Do_Something; Release_Lock; Total_Waiting_Time := Total_Waiting_Time + Clock - Now; end; Of course, this is all expository. You don't want to do that, even when you are writing a simulation package because the language provides two time packages (Ada.Calendar and Ada.Real_Time) plus a type Standard.Duration with many types and conversions already defined. (In addition if you use a predefined time type, you can use it in delay and delay until statements.) -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...