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: bobduff@world.std.com (Robert A Duff) Subject: Re: Side-effect arithmetic again [was: Ada ... in embedded systems] Date: 1996/03/20 Message-ID: #1/1 X-Deja-AN: 143328819 references: <4ik5bm$ogg@dayuc.dayton.saic.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-03-20T00:00:00+00:00 List-Id: In article , Robert I. Eachus wrote: >and decrements what you really want is: > > Inc(Direction); Yeah, but I don't really want to have write a generic instantiation just for this silly little thing. I like the fact that you can do this concisely in C, but if you make me write an instantiation, I'll say, forget it, it's not worth the trouble, I'll just spell it out as "X := X + 1;" Nobody commented on my derived type idea, which I sometimes use in my own code. > And the code for that is fairly trival. I may accept John Volan's >challenge and post a proposed package tomorrow. But I don't think it >needs to be standardized. (The issue I want to think about overnight >is whether the generic formal should be "is range <>" or "is (<>)". range <>, IMHO. > I already know that I want to rewrite the package to: > > procedure Inc(Object: in out Formal_Type); > procedure Inc(Object: in out Formal_Type; By: in Integer); > function Inc(Value: in Formal_Type) return Formal_Type; > function Inc(Value: in Formal_Type; By: in Integer) return Formal_Type; > > Since you want the one parameter forms to inline right. Heh? Not sure what you mean -- the defaulted-parameter version should inline just fine, shouldn't it? Why declare functions? Ada already *has* a perfectly readable functional version -- just say "X + 1". The point of the procedure versions is to avoid writing X twice (where X is more complex than a simple variable name), but there's no such rationale for the functions. Historical note: An early version of Ada 9X made this sort of thing pretty painless: procedure Incr(X: in out Root_Integer'Class); Declare that *once*, and you can say "Incr(X);" for X of any integer type. No instantiations necessary, no need to derive from a "special" integer type. In Ada 95, however, Root_Integer is a name that no user may utter (reminds me of the name of God in some parts of the Bible), and 'Class is not allowed for untagged types. - Bob