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,751584f55705ddb7 X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Side-effect arithmetic again [was: Ada ... in embedded systems] Date: 1996/03/21 Message-ID: #1/1 X-Deja-AN: 143660464 distribution: world references: <4hv2fb$6ra@cville-srv.wam.umd.edu> <4il3ce$fqa@saba.info.ucla.edu> organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.ada Date: 1996-03-21T00:00:00+00:00 List-Id: In article <4iq2ia$lk7@dayuc.dayton.saic.com> John G. Volan writes: > I wasn't throwing down a gauntlet or anything, just throwing out an idea > for consideration ... :-) But since you took the gauntlet back, I'll suggest some of the things I was going to put in: > No need to think about it overnight, _both_ can be done fairly > trivially: (My conclusion was that you really only need one package:) ------------------------------------------------------------------------ generic type Item is (<>); package Discrete_Arithmetic is procedure Increment (This : in out Item); procedure Decrement (This : in out Item); --add procedure Increment (This : in out Item; By: in Positive); procedure Decrement (This : in out Item; By: in Positive); procedure Cycle (This: in out Item); --moved for obvious reasons. pragma Inline (Increment); pragma Inline (Decrement); pragma Inline (Cycle); end Discrete_Arithmetic; ------------------------------------------------------------------------ package body Discrete_Arithmetic is procedure Increment (This : in out Item) is begin This := Item'Succ (This); end Increment; procedure Decrement (This : in out Item) is begin This := Item'Pred (This); end Decrement; procedure Increment (This : in out Item; By: in Positive) is begin This := Item'Val(Item'Pos(This) + By); end Increment; procedure Decrement (This : in out Item; By: in Positive) is begin This := Item'Val(Item'Pos(This) - By); end Decrement; procedure Cycle (This: in out Item) is begin if This = Item'LAST then This := Item'First; else This := Item'Succ(This); end if; end Cycle; end Discrete_Arithmetic; ------------------------------------------------------------------ -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...