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,10444cff97404845 X-Google-Attributes: gid103376,public From: Keith Thompson Subject: Re: C like op= proposal Date: 1999/08/18 Message-ID: #1/1 X-Deja-AN: 514337915 References: <7pefco$v7o$1@nnrp1.deja.com> X-Complaints-To: usenet@nusku.cts.com X-Trace: nusku.cts.com 935005171 24857 198.68.168.21 (18 Aug 1999 19:39:31 GMT) Organization: CTS Network Services NNTP-Posting-Date: 18 Aug 1999 19:39:31 GMT Newsgroups: comp.lang.ada Date: 1999-08-18T19:39:31+00:00 List-Id: Jeff Carter writes: [...] > One problem with this kind of syntax can be seen from the following example: > > type Rec is record > I : Integer; > end record; > > type Rec_Ptr is access all Rec; > > Count : Natural := 0; > > function Side_Effects return Rec_Ptr is > Result : Rec_Pointer := new Rec; > begin -- Side_Effects > Count := Count + 1; > Result.I := Count; > > return Result; > end Side_Effects; > > ... > > Side_Effects.I := @ + @ / 2 + 1; > > What is the value of Count after executing this statement? No problem; the value of Count is 1. An occurrence of @ doesn't cause the left hand side to be re-evaluated, it merely refers to the object whose name has already been evaluated. (At least that's how I'd define it.) More precisely, the statement Side_Effects.I := @ + @ / 2 + 1; would be equivalent to declare _LHS_ : _some_type_ renames Side_Effects.I; begin _LHS_ := _LHS_ + _LHS_ / 2 + 1; end; with the proper substitutions for _LHS_ and _some_type_. I don't think defining the semantics is terribly difficult. The real issue is that most people here seem to think it's unbearably ugly. I don't agree -- it's not exactly pretty, but I think the convenience would be worth it. Perhaps I've been contaminated by several years of C and Perl. I suspect a syntax other than @ would make it more bearable to some -- perhaps a new reserved word. Others have suggested things like a generic Inc procedure or a renames declaration to achieve similar effects. These work, but I haven't seen them used much in practice. The reason: they both require an extra declaration, and possibly a new scope, for something that's supposed to be a shorthand within a single assignment statement. Remember that C's funky operators like ++, +=, and so on are dangerous largely because they have side effects *and* return results. (So does ordinary assignment.) The proposed @ shorthand doesn't have this problem. For example, C lets you write thinks like "i = i++", which produces undefined behavior; the @ shorthand doesn't allow such things. I'm well aware that there's little or no chance of this being added to some future version of Ada (which makes this whole thread somewhat off-topic, I suppose). I'm just saying that I like the idea, and I wouldn't mind seeing it in some future language. -- Keith Thompson (The_Other_Keith) kst@cts.com San Diego Supercomputer Center <*> One of the great tragedies of ancient history is that Helen of Troy lived before the invention of the champagne bottle.